Ardour  9.0-pre0-582-g084a23a80d
midi_surface.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #define ABSTRACT_UI_EXPORTS
20 #include "pbd/abstract_ui.h"
21 
23 #include "midi++/types.h"
24 
25 #include "midi_byte_array.h"
26 
27 namespace MIDI {
28  class Parser;
29  class Port;
30 }
31 
32 namespace ARDOUR {
33  class Bundle;
34  class Port;
35  class MidiBuffer;
36 }
37 
38 struct MidiSurfaceRequest : public BaseUI::BaseRequestObject {
39  public:
42 };
43 
45  , public AbstractUI<MidiSurfaceRequest>
46 {
47  public:
48  MIDISurface (ARDOUR::Session&, std::string const & name, std::string const & port_name_prefix, bool use_pad_filter);
50 
51  std::shared_ptr<ARDOUR::Port> input_port();
52  std::shared_ptr<ARDOUR::Port> output_port();
53 
54  // Bundle to represent our input ports
55  std::shared_ptr<ARDOUR::Bundle> _input_bundle;
56  // Bundle to represent our output ports
57  std::shared_ptr<ARDOUR::Bundle> _output_bundle;
58 
60 
61  /* These two names are used in a port registration handler to try to
62  automatically connect the device when it is discovered.
63 
64  If the value returned by these methods begins with a colon, they
65  will be assumed to be regular expressions, and passed (without the
66  leading colon) into the constructor of a std::regex using
67  std::regex::extended syntax.
68 
69  Otherwise, they are assumed to be unique string identifiers, and are
70  merely searched for in port names with std::string::find().
71  */
72  virtual std::string input_port_name () const = 0;
73  virtual std::string output_port_name () const = 0;
74 
75  void write (const MidiByteArray&);
76  void write (MIDI::byte const *, size_t);
77 
78  XMLNode& get_state() const;
79  int set_state (const XMLNode & node, int version);
80 
81  std::list<std::shared_ptr<ARDOUR::Bundle> > bundles ();
82 
84 
86 
87  virtual bool midi_input_handler (Glib::IOCondition ioc, MIDI::Port* port);
89 
90  protected:
92  bool _in_use;
94  std::string port_name_prefix;
97 
98  std::shared_ptr<ARDOUR::Port> _async_in;
99  std::shared_ptr<ARDOUR::Port> _async_out;
100 
102 
103  virtual void connect_to_parser ();
110  virtual void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t) {}
111 
112 
113  virtual void thread_init ();
114 
116 
117  virtual void connect_session_signals ();
118  virtual void notify_record_state_changed () {}
120  virtual void notify_loop_state_changed () {}
121  virtual void notify_parameter_changed (std::string) {}
122  virtual void notify_solo_active_changed (bool) {}
123 
124  virtual void port_registration_handler ();
125  virtual bool pad_filter (ARDOUR::MidiBuffer& in, ARDOUR::MidiBuffer& out) const { return false; }
126 
129  OutputConnected = 0x2
130  };
131 
133 
135 
136  virtual int ports_acquire ();
137  virtual void ports_release ();
138 
139  virtual int begin_using_device ();
140  virtual int stop_using_device ();
141  virtual int device_acquire () = 0;
142  virtual void device_release () = 0;
143 
144  void drop ();
145  void port_setup ();
146 
147  private:
148  bool connection_handler (std::weak_ptr<ARDOUR::Port>, std::string name1, std::weak_ptr<ARDOUR::Port>, std::string name2, bool yn);
149 };
virtual std::string name() const
ARDOUR::Session * session
Definition: basic_ui.h:201
virtual void handle_midi_sysex(MIDI::Parser &, MIDI::byte *, size_t)
Definition: midi_surface.h:110
virtual void port_registration_handler()
void write(const MidiByteArray &)
std::shared_ptr< ARDOUR::Bundle > _output_bundle
Definition: midi_surface.h:57
virtual std::string input_port_name() const =0
void midi_connectivity_established(bool)
std::shared_ptr< ARDOUR::Port > output_port()
virtual void handle_midi_note_on_message(MIDI::Parser &, MIDI::EventTwoBytes *)
Definition: midi_surface.h:108
std::list< std::shared_ptr< ARDOUR::Bundle > > bundles()
PBD::ScopedConnectionList session_connections
Definition: midi_surface.h:115
CONTROL_PROTOCOL_THREADS_NEED_TEMPO_MAP_DECL()
MIDISurface(ARDOUR::Session &, std::string const &name, std::string const &port_name_prefix, bool use_pad_filter)
std::shared_ptr< ARDOUR::Port > _async_out
Definition: midi_surface.h:99
int set_state(const XMLNode &node, int version)
std::shared_ptr< ARDOUR::Port > input_port()
std::shared_ptr< ARDOUR::Bundle > _input_bundle
Definition: midi_surface.h:55
MIDI::Port * _input_port
Definition: midi_surface.h:95
virtual void device_release()=0
ARDOUR::Session & get_session()
Definition: midi_surface.h:59
virtual void notify_record_state_changed()
Definition: midi_surface.h:118
virtual int stop_using_device()
bool with_pad_filter
Definition: midi_surface.h:91
virtual void handle_midi_controller_message(MIDI::Parser &, MIDI::EventTwoBytes *)
Definition: midi_surface.h:107
virtual void connect_to_parser()
virtual void connect_to_port_parser(MIDI::Port &)
bool _data_required
Definition: midi_surface.h:93
void write(MIDI::byte const *, size_t)
virtual void thread_init()
virtual void handle_midi_note_off_message(MIDI::Parser &, MIDI::EventTwoBytes *)
Definition: midi_surface.h:109
std::shared_ptr< ARDOUR::Port > _async_in
Definition: midi_surface.h:98
virtual void notify_parameter_changed(std::string)
Definition: midi_surface.h:121
virtual std::string output_port_name() const =0
virtual bool pad_filter(ARDOUR::MidiBuffer &in, ARDOUR::MidiBuffer &out) const
Definition: midi_surface.h:125
virtual void notify_loop_state_changed()
Definition: midi_surface.h:120
virtual int begin_using_device()
virtual void ports_release()
MIDI::Port * _output_port
Definition: midi_surface.h:96
bool connection_handler(std::weak_ptr< ARDOUR::Port >, std::string name1, std::weak_ptr< ARDOUR::Port >, std::string name2, bool yn)
virtual int ports_acquire()
virtual bool midi_input_handler(Glib::IOCondition ioc, MIDI::Port *port)
int _connection_state
Definition: midi_surface.h:132
XMLNode & get_state() const
void do_request(MidiSurfaceRequest *)
virtual void notify_solo_active_changed(bool)
Definition: midi_surface.h:122
PBD::ScopedConnectionList port_connections
Definition: midi_surface.h:134
virtual void handle_midi_polypressure_message(MIDI::Parser &, MIDI::EventTwoBytes *)
Definition: midi_surface.h:106
PBD::Signal< void()> ConnectionChange
Definition: midi_surface.h:83
virtual void notify_transport_state_changed()
Definition: midi_surface.h:119
virtual void handle_midi_pitchbend_message(MIDI::Parser &, MIDI::pitchbend_t)
Definition: midi_surface.h:105
virtual void connect_session_signals()
void port_setup()
virtual int device_acquire()=0
std::string port_name_prefix
Definition: midi_surface.h:94
Definition: xml++.h:114
unsigned short pitchbend_t