diff options
| -rw-r--r-- | MIDI.cpp | 20 | ||||
| -rw-r--r-- | MIDI.h | 4 | 
2 files changed, 18 insertions, 6 deletions
| @@ -1,6 +1,11 @@  #include "MIDI.h" -MIDI::MIDI() +MIDI::MIDI(): +  seq_handle{}, +  in_port{}, +  npfd{}, +  pfd{}, +  midi_event_parser{}  {    if (0 > snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_INPUT, SND_SEQ_NONBLOCK))    { @@ -64,10 +69,15 @@ MIDI::MIDI()    } else if (fd() <= 2) {      std::cout << "Warning: Bad MIDI fd: " << std::to_string(fd()) << std::endl;    } + +  if (0 > snd_midi_event_new(1024, &midi_event_parser)) { +    throw std::runtime_error("snd_midi_event_new()"); +  }  }  MIDI::~MIDI()  { +  snd_midi_event_free(midi_event_parser);    free(pfd);  } @@ -91,7 +101,7 @@ snd_seq_event_t* MIDI::read(void)    snd_seq_event_t *ev = NULL;    if (0 > snd_seq_event_input(seq_handle, &ev))    { -   std::cerr << "snd_seq_event_input(): -EAGAIN" << std::endl; +    std::cerr << "snd_seq_event_input(): -EAGAIN" << std::endl;    }    return ev; @@ -153,8 +163,10 @@ void MIDI::process(snd_seq_event_t *ev)      log_cout << fmt::format("[{}] Unknown MIDI event: {}", timestamp_from_event(ev), ev->type) << std::endl;    } -  signal_count_events(snd_seq_event_length(ev)); -  //log_cout << fmt::format("MIDI Bytes: {}", snd_seq_event_length(ev)) << std::endl; +  unsigned char buf[1024]; // dummy +  long midi_bytes {snd_midi_event_decode(midi_event_parser, buf, sizeof(buf), ev)}; + +  signal_count_events(midi_bytes);  }  void MIDI::flush() @@ -5,9 +5,8 @@  #include "log.h"  #include <boost/signals2.hpp> - +#include <alsa/asoundlib.h>  #include <fmt/format.h> -  #include <iostream>  class MIDI @@ -39,5 +38,6 @@ private:    int in_port;    int npfd;    struct pollfd* pfd; +  snd_midi_event_t* midi_event_parser;  }; | 
