sequencer
rtmidi.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <RtMidi.h>
6 #include <cassert>
7 #include <string>
8 #include <vector>
9 
10 namespace sequencer::backend
11 {
13  {
14  public:
15  void select_output_port( int idx )
16  {
17  SEQUENCER_ASSERT( idx >= 0 )
18  SEQUENCER_ASSERT( idx <= int( midiout_->getPortCount() ) + 1 )
19 
20  midiout_ = std::make_shared< RtMidiOut >();
21  if ( idx == 0 )
22  {
23  return;
24  }
25  midiout_->openPort( unsigned( idx - 1 ) );
26  }
27 
28  std::vector< std::string > available_output_ports()
29  {
30  std::vector< std::string > ports;
31  for ( auto id = 0u; id < midiout_->getPortCount(); ++id )
32  {
33  ports.push_back( midiout_->getPortName( id ) );
34  }
35  return ports;
36  }
37 
39  {
40  return rtmidi::message_sender{*midiout_};
41  }
42 
43  private:
44  std::shared_ptr< RtMidiOut > midiout_ = std::make_shared< RtMidiOut >();
45  };
46 
48  {
49  public:
50  template < class Callback >
51  explicit rtmidi_receiver_t( Callback callback )
52  {
53  midiin_.setCallback( callback );
54  // Don't ignore sysex, timing, or active sensing messages.
55  midiin_.ignoreTypes( false, false, false );
56  }
57 
58  void select_input_port( int idx )
59  {
60  SEQUENCER_ASSERT( idx >= 0 )
61  SEQUENCER_ASSERT( idx <= int( midiin_.getPortCount() ) + 1 )
62 
63  if ( midiin_.isPortOpen() )
64  {
65  midiin_.closePort();
66  }
67  if ( idx == 0 )
68  {
69  return;
70  }
71  midiin_.openPort( unsigned( idx - 1 ) );
72  }
73 
74  std::vector< std::string > available_input_ports()
75  {
76  std::vector< std::string > ports;
77  for ( auto id = 0u; id < midiin_.getPortCount(); ++id )
78  {
79  ports.push_back( midiin_.getPortName( id ) );
80  }
81  return ports;
82  }
83 
84  private:
85  RtMidiIn midiin_{};
86  };
87 } // namespace sequencer::backend
rtmidi_receiver_t(Callback callback)
Definition: rtmidi.hpp:51
void select_input_port(int idx)
Definition: rtmidi.hpp:58
std::vector< std::string > available_input_ports()
Definition: rtmidi.hpp:74
#define SEQUENCER_ASSERT(cond)
Definition: assert.hpp:8
void select_output_port(int idx)
Definition: rtmidi.hpp:15
Definition: clock.hpp:9
rtmidi::message_sender sender() noexcept
Definition: rtmidi.hpp:38
Definition: util.hpp:51
Definition: rtmidi.hpp:12
std::vector< std::string > available_output_ports()
Definition: rtmidi.hpp:28
Definition: rtmidi.hpp:47