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