2 Copyright (C) 2006,2007 John Anderson
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.
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.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "surface_port.h"
23 #include <midi++/types.h>
24 #include <sigc++/signal.h>
25 #include <sigc++/connection.h>
27 #include <glibmm/thread.h>
29 #include "midi_byte_array.h"
37 class MackieControlProtocol;
42 class MackiePort : public SurfacePort
45 enum port_type_t { mcu, ext };
46 enum emulation_t { none, mackie, bcf2000 };
48 MackiePort( MackieControlProtocol & mcp, MIDI::Port & port, int number, port_type_t = mcu );
54 /// MCU and extenders have different sysex headers
55 virtual const MidiByteArray & sysex_hdr() const;
57 /// Handle device initialisation
58 void handle_midi_sysex( MIDI::Parser &, MIDI::byte *, size_t count );
60 /// Handle all control messags
61 void handle_midi_any( MIDI::Parser &, MIDI::byte *, size_t count );
63 Control & lookup_control( MIDI::byte *, size_t count );
65 /// return the number of strips associated with this port
66 virtual int strips() const;
68 /// Block until the port has finished initialising, and then return
69 /// whether the intialisation succeeded
72 emulation_t emulation() const { return _emulation; }
74 /// Connect the any signal from the parser to handle_midi_any
75 /// unless it's already connected
80 The initialisation sequence is fairly complex. First a lock is acquired
81 so that a condition can be used to signal the end of the init process.
82 Then a sysex is sent to the device. The response to the sysex
83 is handled by a switch in handle_midi_sysex which calls one of the
86 However, windows DAWs ignore the documented init sequence and so we
87 do too. Thanks to Essox for helping with this.
89 So we use the version firmware to figure out what device is on
90 the other end of the cable.
95 Once the device is initialised, finalise_init(true) is called, which
96 releases the lock and signals the condition, and starts handling incoming
97 messages. finalise_init(false) will also release the lock but doesn't
98 start handling messages.
100 void finalise_init( bool yn );
102 MidiByteArray host_connection_query( MidiByteArray & bytes );
103 MidiByteArray host_connection_confirmation( const MidiByteArray & bytes );
106 Will set _emulation to what it thinks is correct, based
107 on responses from the device. Or get/set parameters. Or
108 environment variables. Or existence of a file.
110 void probe_emulation( const MidiByteArray & bytes );
112 /// Handle timeout events set for controls that don't emit
114 bool handle_control_timeout_event ( Control * );
117 MackieControlProtocol & _mcp;
118 port_type_t _port_type;
119 sigc::connection _any;
120 sigc::connection _sysex;
121 emulation_t _emulation;
124 Glib::Cond init_cond;
125 Glib::Mutex init_mutex;