summaryrefslogtreecommitdiff
path: root/libs/midi++2/midi++/mmc.h
blob: bd8c19b6f91c7a49d3c2346890755e39954d1819 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*
    Copyright (C) 2000 Paul Barton-Davis

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#ifndef __midipp_mmc_h_h__
#define __midipp_mmc_h_h__

#include "timecode/time.h"

#include "pbd/signals.h"
#include "pbd/ringbuffer.h"

#include "midi++/libmidi_visibility.h"
#include "midi++/types.h"
#include "midi++/parser.h"

namespace ARDOUR {
	class PortEngine;
}

namespace MIDI {

class Port;
class Parser;
class MachineControlCommand;

/** Class to handle incoming and outgoing MIDI machine control messages */
class LIBMIDIPP_API MachineControl
{
  public:
	typedef PBD::Signal1<void,MachineControl&> MMCSignal;

	enum Command {
		cmdStop = 0x1,
		cmdPlay = 0x2,
		cmdDeferredPlay = 0x3,
		cmdFastForward = 0x4,
		cmdRewind = 0x5,
		cmdRecordStrobe = 0x6,

		cmdRecordExit = 0x7,
		cmdRecordPause = 0x8,
		cmdPause = 0x9,
		cmdEject = 0xA,
		cmdChase = 0xB,
		cmdCommandErrorReset = 0xC,
		cmdMmcReset = 0xD,

		cmdIllegalMackieJogStart = 0x20,
		cmdIllegalMackieJogStop = 0x21,

		cmdWrite = 0x40,
		cmdMaskedWrite = 0x41,
		cmdRead = 0x42,
		cmdUpdate = 0x43,
		cmdLocate = 0x44,
		cmdVariablePlay = 0x45,
		cmdSearch = 0x46,

		cmdShuttle = 0x47,
		cmdStep = 0x48,
		cmdAssignSystemMaster = 0x49,
		cmdGeneratorCommand = 0x4A,
		cmdMtcCommand = 0x4B,
		cmdMove = 0x4C,
		cmdAdd = 0x4D,

		cmdSubtract = 0x4E,
		cmdDropFrameAdjust = 0x4F,
		cmdProcedure = 0x50,
		cmdEvent = 0x51,
		cmdGroup = 0x52,
		cmdCommandSegment = 0x53,
		cmdDeferredVariablePlay = 0x54,

		cmdRecordStrobeVariable = 0x55,

		cmdWait = 0x7C,
		cmdResume = 0x7F
	};

        MachineControl ();

        void set_ports (MIDI::Port* input, MIDI::Port* output);

	Port* input_port() { return _input_port; }
	Port* output_port() { return _output_port; }

	void set_receive_device_id (byte id);
	void set_send_device_id (byte id);
	byte receive_device_id () const { return _receive_device_id; }
	byte send_device_id () const { return _send_device_id; }
	void enable_send (bool);
	bool send_enabled () const { return _enable_send; }
	void send (MachineControlCommand const &, timestamp_t when);

	static bool is_mmc (byte *sysex_buf, size_t len);

	/* Signals to connect to if you want to run "callbacks"
	   when certain MMC commands are received.
	*/

	MMCSignal Stop;
	MMCSignal Play;
	MMCSignal DeferredPlay;
	MMCSignal FastForward;
	MMCSignal Rewind;
	MMCSignal RecordStrobe;
	MMCSignal RecordExit;
	MMCSignal RecordPause;
	MMCSignal Pause;
	MMCSignal Eject;
	MMCSignal Chase;
	MMCSignal CommandErrorReset;
	MMCSignal MmcReset;
	MMCSignal JogStart;
	MMCSignal JogStop;
	MMCSignal Write;
	MMCSignal MaskedWrite;
	MMCSignal Read;
	MMCSignal Update;
	MMCSignal VariablePlay;
	MMCSignal Search;
	MMCSignal AssignSystemMaster;
	MMCSignal GeneratorCommand;
	MMCSignal MidiTimeCodeCommand;
	MMCSignal Move;
	MMCSignal Add;
	MMCSignal Subtract;
	MMCSignal DropFrameAdjust;
	MMCSignal Procedure;
	MMCSignal Event;
	MMCSignal Group;
	MMCSignal CommandSegment;
	MMCSignal DeferredVariablePlay;
	MMCSignal RecordStrobeVariable;
	MMCSignal Wait;
	MMCSignal Resume;

	PBD::Signal0<void> SPPStart;
	PBD::Signal0<void> SPPContinue;
	PBD::Signal0<void> SPPStop;

	/* The second argument is the shuttle speed, the third is
	   true if the direction is "forwards", false for "reverse"
	*/

	PBD::Signal3<void,MachineControl&,float,bool> Shuttle;

	/* The second argument specifies the desired track record enabled
	   status.
	*/

	PBD::Signal3<void,MachineControl &,size_t,bool>
		                             TrackRecordStatusChange;

	/* The second argument specifies the desired track record enabled
	   status.
	*/

	PBD::Signal3<void,MachineControl &,size_t,bool>
		                             TrackMuteChange;

	/* The second argument points to a byte array containing
	   the locate target value in MMC Standard Time Code
	   format (5 bytes, roughly: hrs/mins/secs/samples/subframes)
	*/

	PBD::Signal2<void,MachineControl &, const byte *> Locate;

	/* The second argument is the number of steps to jump */

	PBD::Signal2<void,MachineControl &, int> Step;

#define MMC_NTRACKS 48

	/* note: these are not currently in use */

	byte updateRate;
	byte responseError;
	byte commandError;
	byte commandErrorLevel;

	byte motionControlTally;
	byte velocityTally;
	byte stopMode;
	byte fastMode;
	byte recordMode;
	byte recordStatus;
	bool trackRecordStatus[MMC_NTRACKS];
	bool trackRecordReady[MMC_NTRACKS];
	byte globalMonitor;
	byte recordMonitor;
	byte trackSyncMonitor;
	byte trackInputMonitor;
	byte stepLength;
	byte playSpeedReference;
	byte fixedSpeed;
	byte lifterDefeat;
	byte controlDisable;
	byte trackMute[MMC_NTRACKS];
	byte failure;
	byte selectedTimeCode;
	byte shortSelectedTimeCode;
	byte timeStandard;
	byte selectedTimeCodeSource;
	byte selectedTimeCodeUserbits;
	byte selectedMasterCode;
	byte requestedOffset;
	byte actualOffset;
	byte lockDeviation;
	byte shortSelectedMasterCode;
	byte shortRequestedOffset;
	byte shortActualOffset;
	byte shortLockDeviation;
	byte resolvedPlayMode;
	byte chaseMode;
	byte generatorTimeCode;
	byte shortGeneratorTimeCode;
	byte generatorCommandTally;
	byte generatorSetUp;
	byte generatorUserbits;
	byte vitcInsertEnable;
	byte midiTimeCodeInput;
	byte shortMidiTimeCodeInput;
	byte midiTimeCodeCommandTally;
	byte midiTimeCodeSetUp;
	byte gp0;
	byte gp1;
	byte gp2;
	byte gp3;
	byte gp4;
	byte gp5;
	byte gp6;
	byte gp7;
	byte shortGp0;
	byte shortGp1;
	byte shortGp2;
	byte shortGp3;
	byte shortGp4;
	byte shortGp5;
	byte shortGp6;
	byte shortGp7;
	byte procedureResponse;
	byte eventResponse;
	byte responseSegment;
	byte wait;
	byte resume;

  private:
	byte _receive_device_id;
	byte _send_device_id;
	Port* _input_port;
	Port* _output_port;
	bool _enable_send; ///< true if MMC sending is enabled

	void process_mmc_message (Parser &p, byte *, size_t len);
	PBD::ScopedConnectionList port_connections; ///< connections to our parser for incoming data

	int  do_masked_write (byte *, size_t len);
	int  do_locate (byte *, size_t len);
	int  do_step (byte *, size_t len);
	int  do_shuttle (byte *, size_t len);

	void write_track_status (byte *, size_t len, byte reg);
	void spp_start ();
	void spp_continue ();
	void spp_stop ();
};

/** Class to describe a MIDI machine control command to be sent.
 *  In an ideal world we might use a class hierarchy for this, but objects of this type
 *  have to be allocated off the stack for RT safety.
 */
class LIBMIDIPP_API MachineControlCommand
{
public:
	MachineControlCommand () : _command (MachineControl::Command (0)) {}
	MachineControlCommand (MachineControl::Command);
	MachineControlCommand (Timecode::Time);

	MIDI::byte* fill_buffer (MachineControl *mmc, MIDI::byte *) const;

private:
	MachineControl::Command _command;
	Timecode::Time _time;
};

} // namespace MIDI

#endif /* __midipp_mmc_h_h__ */