2008-06-02 17:41:35 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 1998 Paul Barton-Davis
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
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 __midi_parse_h__
|
|
|
|
#define __midi_parse_h__
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
|
2009-12-19 15:26:31 -05:00
|
|
|
#include "pbd/signals.h"
|
2008-06-02 17:41:35 -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"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
namespace MIDI {
|
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
class Port;
|
2008-06-02 17:41:35 -04:00
|
|
|
class Parser;
|
|
|
|
|
2009-12-19 15:26:31 -05:00
|
|
|
typedef PBD::Signal1<void,Parser&> ZeroByteSignal;
|
2014-04-28 19:58:24 -04:00
|
|
|
typedef PBD::Signal2<void,Parser&,unsigned short> BankSignal;
|
2018-09-25 17:46:49 -04:00
|
|
|
typedef PBD::Signal2<void,Parser&,samplecnt_t> TimestampedSignal;
|
2009-12-19 15:26:31 -05:00
|
|
|
typedef PBD::Signal2<void,Parser&, byte> OneByteSignal;
|
|
|
|
typedef PBD::Signal2<void,Parser &, EventTwoBytes *> TwoByteSignal;
|
|
|
|
typedef PBD::Signal2<void,Parser &, pitchbend_t> PitchBendSignal;
|
2015-11-23 11:49:08 -05:00
|
|
|
typedef PBD::Signal3<void,Parser &, uint16_t, int> RPNSignal;
|
|
|
|
typedef PBD::Signal3<void,Parser &, uint16_t, float> RPNValueSignal;
|
2009-12-19 15:26:31 -05:00
|
|
|
typedef PBD::Signal3<void,Parser &, byte *, size_t> Signal;
|
2018-09-18 18:51:59 -04:00
|
|
|
typedef PBD::Signal4<void,Parser &, byte *, size_t, samplecnt_t> AnySignal;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2013-10-17 10:27:04 -04:00
|
|
|
class LIBMIDIPP_API Parser {
|
2008-06-02 17:41:35 -04:00
|
|
|
public:
|
2013-08-07 22:22:11 -04:00
|
|
|
Parser ();
|
2008-06-02 17:41:35 -04:00
|
|
|
~Parser ();
|
2009-12-01 13:31:00 -05:00
|
|
|
|
|
|
|
/* sets the time that will be reported for any MTC or MIDI Clock
|
|
|
|
message the next time ::scanner() parses such a message. It should
|
|
|
|
therefore be set before every byte passed into ::scanner().
|
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t get_timestamp() const { return _timestamp; }
|
|
|
|
void set_timestamp (const samplecnt_t timestamp) { _timestamp = timestamp; }
|
2009-12-01 13:31:00 -05:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
/* signals that anyone can connect to */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-04-28 19:58:24 -04:00
|
|
|
BankSignal bank_change;
|
2008-06-02 17:41:35 -04:00
|
|
|
TwoByteSignal note_on;
|
|
|
|
TwoByteSignal note_off;
|
|
|
|
TwoByteSignal poly_pressure;
|
|
|
|
OneByteSignal pressure;
|
|
|
|
OneByteSignal program_change;
|
|
|
|
PitchBendSignal pitchbend;
|
|
|
|
TwoByteSignal controller;
|
|
|
|
|
2014-04-28 19:58:24 -04:00
|
|
|
BankSignal channel_bank_change[16];
|
2008-06-02 17:41:35 -04:00
|
|
|
TwoByteSignal channel_note_on[16];
|
|
|
|
TwoByteSignal channel_note_off[16];
|
|
|
|
TwoByteSignal channel_poly_pressure[16];
|
|
|
|
OneByteSignal channel_pressure[16];
|
|
|
|
OneByteSignal channel_program_change[16];
|
|
|
|
PitchBendSignal channel_pitchbend[16];
|
|
|
|
TwoByteSignal channel_controller[16];
|
2009-12-17 13:24:23 -05:00
|
|
|
ZeroByteSignal channel_active_preparse[16];
|
|
|
|
ZeroByteSignal channel_active_postparse[16];
|
2015-11-23 12:25:59 -05:00
|
|
|
RPNValueSignal channel_rpn[16];
|
|
|
|
RPNValueSignal channel_nrpn[16];
|
|
|
|
RPNSignal channel_rpn_change[16];
|
|
|
|
RPNSignal channel_nrpn_change[16];
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-12-01 13:31:00 -05:00
|
|
|
OneByteSignal mtc_quarter_frame; /* see below for more useful signals */
|
|
|
|
Signal mtc;
|
2008-06-02 17:41:35 -04:00
|
|
|
Signal raw_preparse;
|
|
|
|
Signal raw_postparse;
|
2018-09-18 18:51:59 -04:00
|
|
|
AnySignal any;
|
2008-06-02 17:41:35 -04:00
|
|
|
Signal sysex;
|
|
|
|
Signal mmc;
|
2018-09-25 17:46:49 -04:00
|
|
|
AnySignal position;
|
2008-06-02 17:41:35 -04:00
|
|
|
Signal song;
|
|
|
|
|
2009-12-17 13:24:23 -05:00
|
|
|
ZeroByteSignal all_notes_off;
|
|
|
|
ZeroByteSignal tune;
|
|
|
|
ZeroByteSignal active_sense;
|
|
|
|
ZeroByteSignal reset;
|
|
|
|
ZeroByteSignal eox;
|
|
|
|
|
|
|
|
TimestampedSignal timing;
|
|
|
|
TimestampedSignal start;
|
|
|
|
TimestampedSignal stop;
|
|
|
|
TimestampedSignal contineu; /* note spelling */
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
/* This should really be protected, but then derivatives of Port
|
|
|
|
can't access it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void scanner (byte c);
|
|
|
|
|
|
|
|
size_t *message_counts() { return message_counter; }
|
|
|
|
const char *midi_event_type_name (MIDI::eventType);
|
|
|
|
void trace (bool onoff, std::ostream *o, const std::string &prefix = "");
|
|
|
|
bool tracing() { return trace_stream != 0; }
|
|
|
|
|
|
|
|
void set_offline (bool);
|
|
|
|
bool offline() const { return _offline; }
|
2009-12-19 15:26:31 -05:00
|
|
|
PBD::Signal0<void> OfflineStatusChanged;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-12-19 15:26:31 -05:00
|
|
|
PBD::Signal2<int,byte *, size_t> edit;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
void set_mmc_forwarding (bool yn) {
|
|
|
|
_mmc_forward = yn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* MTC */
|
|
|
|
|
|
|
|
MTC_FPS mtc_fps() const { return _mtc_fps; }
|
|
|
|
MTC_Status mtc_running() const { return _mtc_running; }
|
|
|
|
const byte *mtc_current() const { return _mtc_time; }
|
|
|
|
bool mtc_locked() const { return _mtc_locked; }
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
PBD::Signal3<void, Parser &, int, samplecnt_t> mtc_qtr;
|
|
|
|
PBD::Signal3<void, const byte *, bool, samplecnt_t> mtc_time;
|
2010-12-03 17:26:29 -05:00
|
|
|
PBD::Signal1<void, MTC_Status> mtc_status;
|
|
|
|
PBD::Signal0<bool> mtc_skipped;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
void set_mtc_forwarding (bool yn) {
|
|
|
|
_mtc_forward = yn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset_mtc_state ();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
private:
|
|
|
|
/* tracing */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
std::ostream *trace_stream;
|
|
|
|
std::string trace_prefix;
|
2018-09-18 18:51:59 -04:00
|
|
|
void trace_event (Parser &p, byte *msg, size_t len, samplecnt_t);
|
2009-12-19 15:26:31 -05:00
|
|
|
PBD::ScopedConnection trace_connection;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
size_t message_counter[256];
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
enum ParseState {
|
2008-06-02 17:41:35 -04:00
|
|
|
NEEDSTATUS,
|
|
|
|
NEEDONEBYTE,
|
|
|
|
NEEDTWOBYTES,
|
|
|
|
VARIABLELENGTH
|
|
|
|
};
|
|
|
|
ParseState state;
|
|
|
|
unsigned char *msgbuf;
|
|
|
|
int msglen;
|
|
|
|
int msgindex;
|
|
|
|
MIDI::eventType msgtype;
|
|
|
|
channel_t channel;
|
|
|
|
bool _offline;
|
|
|
|
bool runnable;
|
|
|
|
bool was_runnable;
|
|
|
|
bool _mmc_forward;
|
|
|
|
bool _mtc_forward;
|
|
|
|
int expected_mtc_quarter_frame_code;
|
|
|
|
byte _mtc_time[5];
|
|
|
|
byte _qtr_mtc_time[5];
|
2017-09-18 12:39:17 -04:00
|
|
|
unsigned long consecutive_qtr_sample_cnt;
|
2008-06-02 17:41:35 -04:00
|
|
|
MTC_FPS _mtc_fps;
|
|
|
|
MTC_Status _mtc_running;
|
|
|
|
bool _mtc_locked;
|
2017-09-18 12:39:17 -04:00
|
|
|
byte last_qtr_sample;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t _timestamp;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
ParseState pre_variable_state;
|
|
|
|
MIDI::eventType pre_variable_msgtype;
|
|
|
|
byte last_status_byte;
|
|
|
|
|
|
|
|
void channel_msg (byte);
|
|
|
|
void realtime_msg (byte);
|
|
|
|
void system_msg (byte);
|
|
|
|
void signal (byte *msg, size_t msglen);
|
|
|
|
bool possible_mmc (byte *msg, size_t msglen);
|
|
|
|
bool possible_mtc (byte *msg, size_t msglen);
|
|
|
|
void process_mtc_quarter_frame (byte *msg);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace MIDI
|
|
|
|
|
|
|
|
#endif // __midi_parse_h__
|
|
|
|
|