2008-06-02 17:41:35 -04:00
|
|
|
/*
|
2019-08-02 23:10:55 -04:00
|
|
|
* Copyright (C) 2000-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
|
|
|
|
* Copyright (C) 2009-2010 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2010-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2024-09-25 20:38:49 -04:00
|
|
|
#pragma once
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2017-09-24 12:03:54 -04:00
|
|
|
#include "temporal/time.h"
|
2013-07-24 19:29:45 -04:00
|
|
|
|
2009-12-19 15:26:31 -05:00
|
|
|
#include "pbd/signals.h"
|
2010-06-29 09:47:53 -04:00
|
|
|
#include "pbd/ringbuffer.h"
|
2013-07-24 19:29:45 -04:00
|
|
|
|
2013-10-17 10:27:04 -04:00
|
|
|
#include "midi++/libmidi_visibility.h"
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "midi++/types.h"
|
2010-07-02 20:11:33 -04:00
|
|
|
#include "midi++/parser.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
namespace ARDOUR {
|
|
|
|
class PortEngine;
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
namespace MIDI {
|
|
|
|
|
|
|
|
class Port;
|
|
|
|
class Parser;
|
2010-07-02 20:11:33 -04:00
|
|
|
class MachineControlCommand;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2010-06-29 09:47:53 -04:00
|
|
|
/** Class to handle incoming and outgoing MIDI machine control messages */
|
2015-10-04 14:51:05 -04:00
|
|
|
class LIBMIDIPP_API MachineControl
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
public:
|
2024-10-18 12:01:28 -04:00
|
|
|
typedef PBD::Signal<void(MachineControl&)> MMCSignal;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
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,
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
cmdIllegalMackieJogStart = 0x20,
|
|
|
|
cmdIllegalMackieJogStop = 0x21,
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
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
|
|
|
|
};
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-08-07 22:22:11 -04:00
|
|
|
MachineControl ();
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2013-08-07 22:22:11 -04:00
|
|
|
void set_ports (MIDI::Port* input, MIDI::Port* output);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2010-08-01 06:26:19 -04:00
|
|
|
Port* input_port() { return _input_port; }
|
2010-07-06 20:40:58 -04:00
|
|
|
Port* output_port() { return _output_port; }
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
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; }
|
2010-06-29 09:47:53 -04:00
|
|
|
void enable_send (bool);
|
2012-02-06 12:09:53 -05:00
|
|
|
bool send_enabled () const { return _enable_send; }
|
2014-10-22 17:06:33 -04:00
|
|
|
void send (MachineControlCommand const &, timestamp_t when);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-17 13:24:23 -05:00
|
|
|
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;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2024-10-18 12:01:28 -04:00
|
|
|
PBD::Signal<void()> SPPStart;
|
|
|
|
PBD::Signal<void()> SPPContinue;
|
|
|
|
PBD::Signal<void()> SPPStop;
|
2010-07-02 20:11:33 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
/* The second argument is the shuttle speed, the third is
|
|
|
|
true if the direction is "forwards", false for "reverse"
|
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2024-10-18 12:01:28 -04:00
|
|
|
PBD::Signal<void(MachineControl&,float,bool)> Shuttle;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
/* The second argument specifies the desired track record enabled
|
|
|
|
status.
|
|
|
|
*/
|
|
|
|
|
2024-10-18 12:01:28 -04:00
|
|
|
PBD::Signal<void(MachineControl &,size_t,bool)>
|
2008-06-02 17:41:35 -04:00
|
|
|
TrackRecordStatusChange;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-11-23 12:34:11 -05:00
|
|
|
/* The second argument specifies the desired track record enabled
|
|
|
|
status.
|
|
|
|
*/
|
|
|
|
|
2024-10-18 12:01:28 -04:00
|
|
|
PBD::Signal<void(MachineControl &,size_t,bool)>
|
2009-11-23 12:34:11 -05:00
|
|
|
TrackMuteChange;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
/* The second argument points to a byte array containing
|
|
|
|
the locate target value in MMC Standard Time Code
|
2019-04-07 18:18:08 -04:00
|
|
|
format (5 bytes, roughly: hrs/mins/secs/frames/subframes)
|
2008-06-02 17:41:35 -04:00
|
|
|
*/
|
|
|
|
|
2024-10-18 12:01:28 -04:00
|
|
|
PBD::Signal<void(MachineControl &, const byte *)> Locate;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
/* The second argument is the number of steps to jump */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2024-10-18 12:01:28 -04:00
|
|
|
PBD::Signal<void(MachineControl &, int)> Step;
|
2010-06-29 10:04:19 -04:00
|
|
|
|
|
|
|
#define MMC_NTRACKS 48
|
|
|
|
|
|
|
|
/* note: these are not currently in use */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2010-06-29 10:04:19 -04:00
|
|
|
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;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
private:
|
|
|
|
byte _receive_device_id;
|
|
|
|
byte _send_device_id;
|
2010-07-06 20:40:58 -04:00
|
|
|
Port* _input_port;
|
|
|
|
Port* _output_port;
|
2010-06-29 09:47:53 -04:00
|
|
|
bool _enable_send; ///< true if MMC sending is enabled
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
void process_mmc_message (Parser &p, byte *, size_t len);
|
2010-07-02 20:11:33 -04:00
|
|
|
PBD::ScopedConnectionList port_connections; ///< connections to our parser for incoming data
|
2009-12-17 13:24:23 -05:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
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);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-11-23 12:34:11 -05:00
|
|
|
void write_track_status (byte *, size_t len, byte reg);
|
2012-04-11 16:21:00 -04:00
|
|
|
void spp_start ();
|
|
|
|
void spp_continue ();
|
|
|
|
void spp_stop ();
|
2008-06-02 17:41:35 -04:00
|
|
|
};
|
|
|
|
|
2010-06-29 09:47:53 -04:00
|
|
|
/** 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
|
2010-06-29 15:07:22 -04:00
|
|
|
* have to be allocated off the stack for RT safety.
|
2010-06-29 09:47:53 -04:00
|
|
|
*/
|
2013-10-17 10:27:04 -04:00
|
|
|
class LIBMIDIPP_API MachineControlCommand
|
2010-06-29 09:47:53 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
MachineControlCommand () : _command (MachineControl::Command (0)) {}
|
|
|
|
MachineControlCommand (MachineControl::Command);
|
|
|
|
MachineControlCommand (Timecode::Time);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2010-06-29 09:47:53 -04:00
|
|
|
MIDI::byte* fill_buffer (MachineControl *mmc, MIDI::byte *) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
MachineControl::Command _command;
|
|
|
|
Timecode::Time _time;
|
|
|
|
};
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
} // namespace MIDI
|
|
|
|
|