Ardour  9.0-pre0-384-ga76afae0e9
parser.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2018 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
4  * Copyright (C) 2009 David Robillard <d@drobilla.net>
5  * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #pragma once
23 
24 #include <string>
25 #include <iostream>
26 
27 #include "pbd/signals.h"
28 
30 #include "midi++/types.h"
31 
32 namespace MIDI {
33 
34 class Port;
35 class Parser;
36 
38 typedef PBD::Signal<void(Parser&,unsigned short)> BankSignal;
40 typedef PBD::Signal<void(Parser&, byte)> OneByteSignal;
43 typedef PBD::Signal<void(Parser &, uint16_t, int)> RPNSignal;
44 typedef PBD::Signal<void(Parser &, uint16_t, float)> RPNValueSignal;
45 typedef PBD::Signal<void(Parser &, byte *, size_t)> Signal;
46 typedef PBD::Signal<void(Parser &, byte *, size_t, samplecnt_t)> AnySignal;
47 
49  public:
50  Parser ();
51  ~Parser ();
52 
53  /* sets the time that will be reported for any MTC or MIDI Clock
54  message the next time ::scanner() parses such a message. It should
55  therefore be set before every byte passed into ::scanner().
56  */
57 
58  samplecnt_t get_timestamp() const { return _timestamp; }
59  void set_timestamp (const samplecnt_t timestamp) { _timestamp = timestamp; }
60 
61  /* signals that anyone can connect to */
62 
71 
72  BankSignal channel_bank_change[16];
73  TwoByteSignal channel_note_on[16];
74  TwoByteSignal channel_note_off[16];
75  TwoByteSignal channel_poly_pressure[16];
76  OneByteSignal channel_pressure[16];
77  OneByteSignal channel_program_change[16];
78  PitchBendSignal channel_pitchbend[16];
79  TwoByteSignal channel_controller[16];
80  ZeroByteSignal channel_active_preparse[16];
81  ZeroByteSignal channel_active_postparse[16];
82  RPNValueSignal channel_rpn[16];
83  RPNValueSignal channel_nrpn[16];
84  RPNSignal channel_rpn_change[16];
85  RPNSignal channel_nrpn_change[16];
86 
87  OneByteSignal mtc_quarter_frame; /* see below for more useful signals */
96 
102 
104  TimestampedSignal tick; /* rarely seen in the wild */
107  TimestampedSignal contineu; /* note spelling */
108 
109  /* This should really be protected, but then derivatives of Port
110  can't access it.
111  */
112 
113  void scanner (byte c);
114 
115  size_t *message_counts() { return message_counter; }
117  void trace (bool onoff, std::ostream *o, const std::string &prefix = "");
118  bool tracing() { return trace_stream != 0; }
119 
120  void set_offline (bool);
121  bool offline() const { return _offline; }
123 
124  PBD::Signal<int(byte *, size_t)> edit;
125 
126  void set_mmc_forwarding (bool yn) {
127  _mmc_forward = yn;
128  }
129 
130  /* MTC */
131 
132  MTC_FPS mtc_fps() const { return _mtc_fps; }
133  MTC_Status mtc_running() const { return _mtc_running; }
134  const byte *mtc_current() const { return _mtc_time; }
135  bool mtc_locked() const { return _mtc_locked; }
136 
138  PBD::Signal<void(const byte *, bool, samplecnt_t)> mtc_time;
141 
142  void set_mtc_forwarding (bool yn) {
143  _mtc_forward = yn;
144  }
145 
147 
148  private:
149  /* tracing */
150 
151  std::ostream *trace_stream;
152  std::string trace_prefix;
153  void trace_event (Parser &p, byte *msg, size_t len, samplecnt_t);
155 
156  size_t message_counter[256];
157 
158  enum ParseState {
162  VARIABLELENGTH
163  };
165  unsigned char *msgbuf;
166  int msglen;
167  int msgindex;
170  bool _offline;
171  bool runnable;
176  byte _mtc_time[5];
177  byte _qtr_mtc_time[5];
183 
185 
189 
190  void channel_msg (byte);
191  void realtime_msg (byte);
192  void system_msg (byte);
193  void signal (byte *msg, size_t msglen);
194  bool possible_mmc (byte *msg, size_t msglen);
195  bool possible_mtc (byte *msg, size_t msglen);
196  void process_mtc_quarter_frame (byte *msg);
197 };
198 
199 } // namespace MIDI
200 
201 
PitchBendSignal pitchbend
Definition: parser.h:69
Signal song
Definition: parser.h:95
int msgindex
Definition: parser.h:167
PBD::Signal< bool()> mtc_skipped
Definition: parser.h:140
ZeroByteSignal reset
Definition: parser.h:100
void system_msg(byte)
AnySignal position
Definition: parser.h:94
bool _mmc_forward
Definition: parser.h:173
bool possible_mtc(byte *msg, size_t msglen)
AnySignal any
Definition: parser.h:91
void process_mtc_quarter_frame(byte *msg)
const char * midi_event_type_name(MIDI::eventType)
BankSignal bank_change
Definition: parser.h:63
Signal raw_preparse
Definition: parser.h:89
TwoByteSignal poly_pressure
Definition: parser.h:66
PBD::Signal< void(MTC_Status)> mtc_status
Definition: parser.h:139
OneByteSignal mtc_quarter_frame
Definition: parser.h:87
PBD::Signal< int(byte *, size_t)> edit
Definition: parser.h:124
TwoByteSignal note_on
Definition: parser.h:64
MTC_FPS _mtc_fps
Definition: parser.h:179
bool runnable
Definition: parser.h:171
TwoByteSignal note_off
Definition: parser.h:65
PBD::Signal< void()> OfflineStatusChanged
Definition: parser.h:122
void trace(bool onoff, std::ostream *o, const std::string &prefix="")
void set_timestamp(const samplecnt_t timestamp)
Definition: parser.h:59
samplecnt_t get_timestamp() const
Definition: parser.h:58
OneByteSignal program_change
Definition: parser.h:68
TwoByteSignal controller
Definition: parser.h:70
MTC_Status _mtc_running
Definition: parser.h:180
unsigned char * msgbuf
Definition: parser.h:165
bool _offline
Definition: parser.h:170
int expected_mtc_quarter_frame_code
Definition: parser.h:175
MTC_Status mtc_running() const
Definition: parser.h:133
void set_mtc_forwarding(bool yn)
Definition: parser.h:142
OneByteSignal pressure
Definition: parser.h:67
PBD::ScopedConnection trace_connection
Definition: parser.h:154
bool _mtc_forward
Definition: parser.h:174
void channel_msg(byte)
ParseState state
Definition: parser.h:164
bool _mtc_locked
Definition: parser.h:181
MIDI::eventType msgtype
Definition: parser.h:168
@ NEEDONEBYTE
Definition: parser.h:160
@ NEEDTWOBYTES
Definition: parser.h:161
@ NEEDSTATUS
Definition: parser.h:159
TimestampedSignal timing
Definition: parser.h:103
MTC_FPS mtc_fps() const
Definition: parser.h:132
std::string trace_prefix
Definition: parser.h:152
void set_mmc_forwarding(bool yn)
Definition: parser.h:126
ZeroByteSignal tune
Definition: parser.h:98
PBD::Signal< void(Parser &, int, samplecnt_t)> mtc_qtr
Definition: parser.h:137
bool tracing()
Definition: parser.h:118
Signal mtc
Definition: parser.h:88
byte last_qtr_frame
Definition: parser.h:182
PBD::Signal< void(const byte *, bool, samplecnt_t)> mtc_time
Definition: parser.h:138
samplecnt_t _timestamp
Definition: parser.h:184
unsigned long consecutive_qtr_frame_cnt
Definition: parser.h:178
TimestampedSignal stop
Definition: parser.h:106
void signal(byte *msg, size_t msglen)
TimestampedSignal start
Definition: parser.h:105
void trace_event(Parser &p, byte *msg, size_t len, samplecnt_t)
Signal sysex
Definition: parser.h:92
size_t * message_counts()
Definition: parser.h:115
void reset_mtc_state()
bool offline() const
Definition: parser.h:121
int msglen
Definition: parser.h:166
bool was_runnable
Definition: parser.h:172
ZeroByteSignal eox
Definition: parser.h:101
TimestampedSignal contineu
Definition: parser.h:107
void set_offline(bool)
bool mtc_locked() const
Definition: parser.h:135
const byte * mtc_current() const
Definition: parser.h:134
bool possible_mmc(byte *msg, size_t msglen)
ZeroByteSignal active_sense
Definition: parser.h:99
void scanner(byte c)
TimestampedSignal tick
Definition: parser.h:104
Signal mmc
Definition: parser.h:93
ParseState pre_variable_state
Definition: parser.h:186
Signal raw_postparse
Definition: parser.h:90
ZeroByteSignal all_notes_off
Definition: parser.h:97
void realtime_msg(byte)
std::ostream * trace_stream
Definition: parser.h:151
channel_t channel
Definition: parser.h:169
MIDI::eventType pre_variable_msgtype
Definition: parser.h:187
byte last_status_byte
Definition: parser.h:188
#define LIBMIDIPP_API
PBD::Signal< void(Parser &, samplecnt_t)> TimestampedSignal
Definition: parser.h:39
PBD::Signal< void(Parser &, byte *, size_t)> Signal
Definition: parser.h:45
int64_t samplecnt_t
PBD::Signal< void(Parser &)> ZeroByteSignal
Definition: parser.h:35
PBD::Signal< void(Parser &, unsigned short)> BankSignal
Definition: parser.h:38
PBD::Signal< void(Parser &, pitchbend_t)> PitchBendSignal
Definition: parser.h:42
unsigned short pitchbend_t
PBD::Signal< void(Parser &, byte *, size_t, samplecnt_t)> AnySignal
Definition: parser.h:46
PBD::Signal< void(Parser &, byte)> OneByteSignal
Definition: parser.h:40
PBD::Signal< void(Parser &, EventTwoBytes *)> TwoByteSignal
Definition: parser.h:41
PBD::Signal< void(Parser &, uint16_t, float)> RPNValueSignal
Definition: parser.h:44
PBD::Signal< void(Parser &, uint16_t, int)> RPNSignal
Definition: parser.h:43