summaryrefslogtreecommitdiffhomepage
path: root/MIDI.h
blob: ee01f5bbef4b0abd05395b1318978cbc9e8b9a32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once

#include "config.h"
#include "debug.h"
#include "log.h"

#include <boost/signals2.hpp>
#include <alsa/asoundlib.h>
#include <fmt/format.h>
#include <iostream>

class MIDI
{
public:
  MIDI();
  ~MIDI();

  boost::signals2::signal<void(int, int, uint64_t)> signal_note;
  boost::signals2::signal<void()> signal_active_sensing;
  boost::signals2::signal<void()> signal_clock;
  boost::signals2::signal<void(size_t)> signal_count_events;

  int fd();

  bool event_ready();

  snd_seq_event_t *read(void);

  // returns if click starts
  void process(snd_seq_event_t *ev);

  void flush();

  void wait_for_event();

private:
  snd_seq_t *seq_handle;
  int in_port;
  int npfd;
  struct pollfd* pfd;
  snd_midi_event_t* midi_event_parser;
};