rollback to 3428, before the mysterious removal of libs/* at 3431/3432
[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 <sigc++/sigc++.h>
24 #include <midi++/types.h>
25
26 namespace MIDI {
27
28 class Port;
29 class Parser;
30
31 class MachineControl : public sigc::trackable
32
33 {
34   public:
35         typedef byte CommandSignature[60];
36         typedef byte ResponseSignature[60];
37
38         enum Command {
39                 cmdStop = 0x1,
40                 cmdPlay = 0x2,
41                 cmdDeferredPlay = 0x3,
42                 cmdFastForward = 0x4,
43                 cmdRewind = 0x5,
44                 cmdRecordStrobe = 0x6,
45
46                 cmdRecordExit = 0x7,
47                 cmdRecordPause = 0x8,
48                 cmdPause = 0x9,
49                 cmdEject = 0xA,
50                 cmdChase = 0xB,
51                 cmdCommandErrorReset = 0xC,
52                 cmdMmcReset = 0xD,
53                 
54                 cmdIllegalMackieJogStart = 0x20,
55                 cmdIllegalMackieJogStop = 0x21,
56                 
57                 cmdWrite = 0x40,
58                 cmdMaskedWrite = 0x41,
59                 cmdRead = 0x42,
60                 cmdUpdate = 0x43,
61                 cmdLocate = 0x44,
62                 cmdVariablePlay = 0x45,
63                 cmdSearch = 0x46,
64
65                 cmdShuttle = 0x47,
66                 cmdStep = 0x48,
67                 cmdAssignSystemMaster = 0x49,
68                 cmdGeneratorCommand = 0x4A,
69                 cmdMtcCommand = 0x4B,
70                 cmdMove = 0x4C,
71                 cmdAdd = 0x4D,
72
73                 cmdSubtract = 0x4E,
74                 cmdDropFrameAdjust = 0x4F,
75                 cmdProcedure = 0x50,
76                 cmdEvent = 0x51,
77                 cmdGroup = 0x52,
78                 cmdCommandSegment = 0x53,
79                 cmdDeferredVariablePlay = 0x54,
80
81                 cmdRecordStrobeVariable = 0x55,
82
83                 cmdWait = 0x7C,
84                 cmdResume = 0x7F
85         };
86         
87         MachineControl (Port &port,
88                         float MMCVersion, 
89                         CommandSignature &cs,
90                         ResponseSignature &rs);
91
92         Port &port() { return _port; }
93         
94         void set_receive_device_id (byte id);
95         void set_send_device_id (byte id);
96         byte receive_device_id () const { return _receive_device_id; }
97         byte send_device_id () const { return _send_device_id; }
98
99         static bool is_mmc (byte *sysex_buf, size_t len);
100
101         /* Signals to connect to if you want to run "callbacks"
102            when certain MMC commands are received.
103         */
104                         
105         sigc::signal<void,MachineControl &> Stop;
106         sigc::signal<void,MachineControl &> Play;
107         sigc::signal<void,MachineControl &> DeferredPlay;
108         sigc::signal<void,MachineControl &> FastForward;
109         sigc::signal<void,MachineControl &> Rewind;
110         sigc::signal<void,MachineControl &> RecordStrobe;
111         sigc::signal<void,MachineControl &> RecordExit;
112         sigc::signal<void,MachineControl &> RecordPause;
113         sigc::signal<void,MachineControl &> Pause;
114         sigc::signal<void,MachineControl &> Eject;
115         sigc::signal<void,MachineControl &> Chase;
116         sigc::signal<void,MachineControl &> CommandErrorReset;
117         sigc::signal<void,MachineControl &> MmcReset;
118
119         sigc::signal<void,MachineControl &> JogStart;
120         sigc::signal<void,MachineControl &> JogStop;
121
122         sigc::signal<void,MachineControl &> Write;
123         sigc::signal<void,MachineControl &> MaskedWrite;
124         sigc::signal<void,MachineControl &> Read;
125         sigc::signal<void,MachineControl &> Update;
126         sigc::signal<void,MachineControl &> VariablePlay;
127         sigc::signal<void,MachineControl &> Search;
128         sigc::signal<void,MachineControl &> AssignSystemMaster;
129         sigc::signal<void,MachineControl &> GeneratorCommand;
130         sigc::signal<void,MachineControl &> MidiTimeCodeCommand;
131         sigc::signal<void,MachineControl &> Move;
132         sigc::signal<void,MachineControl &> Add;
133         sigc::signal<void,MachineControl &> Subtract;
134         sigc::signal<void,MachineControl &> DropFrameAdjust;
135         sigc::signal<void,MachineControl &> Procedure;
136         sigc::signal<void,MachineControl &> Event;
137         sigc::signal<void,MachineControl &> Group;
138         sigc::signal<void,MachineControl &> CommandSegment;
139         sigc::signal<void,MachineControl &> DeferredVariablePlay;
140         sigc::signal<void,MachineControl &> RecordStrobeVariable;
141         sigc::signal<void,MachineControl &> Wait;
142         sigc::signal<void,MachineControl &> Resume;
143
144         /* The second argument is the shuttle speed, the third is
145            true if the direction is "forwards", false for "reverse"
146         */
147         
148         sigc::signal<void,MachineControl &,float,bool> Shuttle;
149
150         /* The second argument specifies the desired track record enabled
151            status.
152         */
153
154         sigc::signal<void,MachineControl &,size_t,bool> 
155                                              TrackRecordStatusChange;
156         
157         /* The second argument points to a byte array containing
158            the locate target value in MMC Standard Time Code
159            format (5 bytes, roughly: hrs/mins/secs/frames/subframes)
160         */
161
162         sigc::signal<void,MachineControl &, const byte *> Locate;
163
164         /* The second argument is the number of steps to jump */
165         
166         sigc::signal<void,MachineControl &, int> Step;
167         
168   protected:
169
170 #define MMC_NTRACKS 48
171
172         /* MMC Information fields (think "registers") */
173
174         CommandSignature commandSignature;
175         ResponseSignature responseSignature;
176
177         byte updateRate;
178         byte responseError;
179         byte commandError;
180         byte commandErrorLevel;
181         
182         byte motionControlTally;
183         byte velocityTally;
184         byte stopMode;
185         byte fastMode;
186         byte recordMode;
187         byte recordStatus;
188         bool trackRecordStatus[MMC_NTRACKS];
189         bool trackRecordReady[MMC_NTRACKS];
190         byte globalMonitor;
191         byte recordMonitor;
192         byte trackSyncMonitor;
193         byte trackInputMonitor;
194         byte stepLength;
195         byte playSpeedReference;
196         byte fixedSpeed;
197         byte lifterDefeat;
198         byte controlDisable;
199         byte trackMute;
200         byte failure;
201         byte selectedTimeCode;
202         byte shortSelectedTimeCode;
203         byte timeStandard;
204         byte selectedTimeCodeSource;
205         byte selectedTimeCodeUserbits;
206         byte selectedMasterCode;
207         byte requestedOffset;
208         byte actualOffset;
209         byte lockDeviation;
210         byte shortSelectedMasterCode;
211         byte shortRequestedOffset;
212         byte shortActualOffset;
213         byte shortLockDeviation;
214         byte resolvedPlayMode;
215         byte chaseMode;
216         byte generatorTimeCode;
217         byte shortGeneratorTimeCode;
218         byte generatorCommandTally;
219         byte generatorSetUp;
220         byte generatorUserbits;
221         byte vitcInsertEnable;
222         byte midiTimeCodeInput;
223         byte shortMidiTimeCodeInput;
224         byte midiTimeCodeCommandTally;
225         byte midiTimeCodeSetUp;
226         byte gp0;
227         byte gp1;
228         byte gp2;
229         byte gp3;
230         byte gp4;
231         byte gp5;
232         byte gp6;
233         byte gp7;
234         byte shortGp0;
235         byte shortGp1;
236         byte shortGp2;
237         byte shortGp3;
238         byte shortGp4;
239         byte shortGp5;
240         byte shortGp6;
241         byte shortGp7;
242         byte procedureResponse;
243         byte eventResponse;
244         byte responseSegment;
245         byte wait;
246         byte resume;
247
248   private:
249         byte _receive_device_id;
250         byte _send_device_id;
251         MIDI::Port &_port;
252
253         void process_mmc_message (Parser &p, byte *, size_t len);
254         
255         int  do_masked_write (byte *, size_t len);
256         int  do_locate (byte *, size_t len);
257         int  do_step (byte *, size_t len);
258         int  do_shuttle (byte *, size_t len);
259
260         void write_track_record_ready (byte *, size_t len);
261 };
262
263 } // namespace MIDI
264
265 #endif /* __midipp_mmc_h_h__ */