Show matching controller name in automation lane header.
[ardour.git] / libs / midi++2 / midi++ / mmc.h
1 /*
2     Copyright (C) 2000 Paul Barton-Davis 
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
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __midipp_mmc_h_h__
21 #define __midipp_mmc_h_h__
22
23 #include <jack/types.h>
24 #include "timecode/time.h"
25 #include "pbd/signals.h"
26 #include "pbd/ringbuffer.h"
27 #include "midi++/types.h"
28 #include "midi++/parser.h"
29
30 namespace MIDI {
31
32 class Port;
33 class Parser;
34 class MachineControlCommand;
35 class Manager;  
36
37 /** Class to handle incoming and outgoing MIDI machine control messages */
38 class MachineControl 
39 {
40   public:
41         typedef PBD::Signal1<void,MachineControl&> MMCSignal;
42
43         enum Command {
44                 cmdStop = 0x1,
45                 cmdPlay = 0x2,
46                 cmdDeferredPlay = 0x3,
47                 cmdFastForward = 0x4,
48                 cmdRewind = 0x5,
49                 cmdRecordStrobe = 0x6,
50
51                 cmdRecordExit = 0x7,
52                 cmdRecordPause = 0x8,
53                 cmdPause = 0x9,
54                 cmdEject = 0xA,
55                 cmdChase = 0xB,
56                 cmdCommandErrorReset = 0xC,
57                 cmdMmcReset = 0xD,
58                 
59                 cmdIllegalMackieJogStart = 0x20,
60                 cmdIllegalMackieJogStop = 0x21,
61                 
62                 cmdWrite = 0x40,
63                 cmdMaskedWrite = 0x41,
64                 cmdRead = 0x42,
65                 cmdUpdate = 0x43,
66                 cmdLocate = 0x44,
67                 cmdVariablePlay = 0x45,
68                 cmdSearch = 0x46,
69
70                 cmdShuttle = 0x47,
71                 cmdStep = 0x48,
72                 cmdAssignSystemMaster = 0x49,
73                 cmdGeneratorCommand = 0x4A,
74                 cmdMtcCommand = 0x4B,
75                 cmdMove = 0x4C,
76                 cmdAdd = 0x4D,
77
78                 cmdSubtract = 0x4E,
79                 cmdDropFrameAdjust = 0x4F,
80                 cmdProcedure = 0x50,
81                 cmdEvent = 0x51,
82                 cmdGroup = 0x52,
83                 cmdCommandSegment = 0x53,
84                 cmdDeferredVariablePlay = 0x54,
85
86                 cmdRecordStrobeVariable = 0x55,
87
88                 cmdWait = 0x7C,
89                 cmdResume = 0x7F
90         };
91         
92         MachineControl (Manager *, jack_client_t *);
93
94         Port* input_port() { return _input_port; }
95         Port* output_port() { return _output_port; }
96         
97         void set_receive_device_id (byte id);
98         void set_send_device_id (byte id);
99         byte receive_device_id () const { return _receive_device_id; }
100         byte send_device_id () const { return _send_device_id; }
101         void enable_send (bool);
102         bool send_enabled () const { return _enable_send; }
103         void send (MachineControlCommand const &);
104
105         static bool is_mmc (byte *sysex_buf, size_t len);
106
107         /* Signals to connect to if you want to run "callbacks"
108            when certain MMC commands are received.
109         */
110                         
111         MMCSignal Stop;
112         MMCSignal Play;
113         MMCSignal DeferredPlay;
114         MMCSignal FastForward;
115         MMCSignal Rewind;
116         MMCSignal RecordStrobe;
117         MMCSignal RecordExit;
118         MMCSignal RecordPause;
119         MMCSignal Pause;
120         MMCSignal Eject;
121         MMCSignal Chase;
122         MMCSignal CommandErrorReset;
123         MMCSignal MmcReset;
124         MMCSignal JogStart;
125         MMCSignal JogStop;
126         MMCSignal Write;
127         MMCSignal MaskedWrite;
128         MMCSignal Read;
129         MMCSignal Update;
130         MMCSignal VariablePlay;
131         MMCSignal Search;
132         MMCSignal AssignSystemMaster;
133         MMCSignal GeneratorCommand;
134         MMCSignal MidiTimeCodeCommand;
135         MMCSignal Move;
136         MMCSignal Add;
137         MMCSignal Subtract;
138         MMCSignal DropFrameAdjust;
139         MMCSignal Procedure;
140         MMCSignal Event;
141         MMCSignal Group;
142         MMCSignal CommandSegment;
143         MMCSignal DeferredVariablePlay;
144         MMCSignal RecordStrobeVariable;
145         MMCSignal Wait;
146         MMCSignal Resume;
147
148         PBD::Signal0<void> SPPStart;
149         PBD::Signal0<void> SPPContinue;
150         PBD::Signal0<void> SPPStop;
151
152         /* The second argument is the shuttle speed, the third is
153            true if the direction is "forwards", false for "reverse"
154         */
155         
156         PBD::Signal3<void,MachineControl&,float,bool> Shuttle;
157
158         /* The second argument specifies the desired track record enabled
159            status.
160         */
161
162         PBD::Signal3<void,MachineControl &,size_t,bool> 
163                                              TrackRecordStatusChange;
164         
165         /* The second argument specifies the desired track record enabled
166            status.
167         */
168
169         PBD::Signal3<void,MachineControl &,size_t,bool> 
170                                              TrackMuteChange;
171         
172         /* The second argument points to a byte array containing
173            the locate target value in MMC Standard Time Code
174            format (5 bytes, roughly: hrs/mins/secs/frames/subframes)
175         */
176
177         PBD::Signal2<void,MachineControl &, const byte *> Locate;
178
179         /* The second argument is the number of steps to jump */
180         
181         PBD::Signal2<void,MachineControl &, int> Step;
182
183 #define MMC_NTRACKS 48
184
185         /* note: these are not currently in use */
186         
187         byte updateRate;
188         byte responseError;
189         byte commandError;
190         byte commandErrorLevel;
191
192         byte motionControlTally;
193         byte velocityTally;
194         byte stopMode;
195         byte fastMode;
196         byte recordMode;
197         byte recordStatus;
198         bool trackRecordStatus[MMC_NTRACKS];
199         bool trackRecordReady[MMC_NTRACKS];
200         byte globalMonitor;
201         byte recordMonitor;
202         byte trackSyncMonitor;
203         byte trackInputMonitor;
204         byte stepLength;
205         byte playSpeedReference;
206         byte fixedSpeed;
207         byte lifterDefeat;
208         byte controlDisable;
209         byte trackMute[MMC_NTRACKS];
210         byte failure;
211         byte selectedTimeCode;
212         byte shortSelectedTimeCode;
213         byte timeStandard;
214         byte selectedTimeCodeSource;
215         byte selectedTimeCodeUserbits;
216         byte selectedMasterCode;
217         byte requestedOffset;
218         byte actualOffset;
219         byte lockDeviation;
220         byte shortSelectedMasterCode;
221         byte shortRequestedOffset;
222         byte shortActualOffset;
223         byte shortLockDeviation;
224         byte resolvedPlayMode;
225         byte chaseMode;
226         byte generatorTimeCode;
227         byte shortGeneratorTimeCode;
228         byte generatorCommandTally;
229         byte generatorSetUp;
230         byte generatorUserbits;
231         byte vitcInsertEnable;
232         byte midiTimeCodeInput;
233         byte shortMidiTimeCodeInput;
234         byte midiTimeCodeCommandTally;
235         byte midiTimeCodeSetUp;
236         byte gp0;
237         byte gp1;
238         byte gp2;
239         byte gp3;
240         byte gp4;
241         byte gp5;
242         byte gp6;
243         byte gp7;
244         byte shortGp0;
245         byte shortGp1;
246         byte shortGp2;
247         byte shortGp3;
248         byte shortGp4;
249         byte shortGp5;
250         byte shortGp6;
251         byte shortGp7;
252         byte procedureResponse;
253         byte eventResponse;
254         byte responseSegment;
255         byte wait;
256         byte resume;
257         
258   private:
259         byte _receive_device_id;
260         byte _send_device_id;
261         Port* _input_port;
262         Port* _output_port;
263         bool _enable_send; ///< true if MMC sending is enabled
264
265         void process_mmc_message (Parser &p, byte *, size_t len);
266         PBD::ScopedConnectionList port_connections; ///< connections to our parser for incoming data
267
268         int  do_masked_write (byte *, size_t len);
269         int  do_locate (byte *, size_t len);
270         int  do_step (byte *, size_t len);
271         int  do_shuttle (byte *, size_t len);
272         
273         void write_track_status (byte *, size_t len, byte reg);
274         void spp_start ();
275         void spp_continue ();
276         void spp_stop ();
277 };
278
279 /** Class to describe a MIDI machine control command to be sent.
280  *  In an ideal world we might use a class hierarchy for this, but objects of this type
281  *  have to be allocated off the stack for RT safety.
282  */
283 class MachineControlCommand
284 {
285 public:
286         MachineControlCommand () : _command (MachineControl::Command (0)) {}
287         MachineControlCommand (MachineControl::Command);
288         MachineControlCommand (Timecode::Time);
289         
290         MIDI::byte* fill_buffer (MachineControl *mmc, MIDI::byte *) const;
291
292 private:
293         MachineControl::Command _command;
294         Timecode::Time _time;
295 };
296
297 } // namespace MIDI
298
299 #endif /* __midipp_mmc_h_h__ */