2008-06-02 17:41:35 -04:00
|
|
|
/*
|
2019-08-02 23:10:55 -04:00
|
|
|
* Copyright (C) 1998-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2006-2009 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2010 Carl Hetherington <carl@carlh.net>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
#ifndef __midichannel_h__
|
|
|
|
#define __midichannel_h__
|
|
|
|
|
|
|
|
#include <queue>
|
2015-11-23 10:44:40 -05:00
|
|
|
#include <map>
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-12-19 15:26:31 -05:00
|
|
|
#include "pbd/signals.h"
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "midi++/parser.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
namespace MIDI {
|
|
|
|
|
|
|
|
class Port;
|
|
|
|
|
|
|
|
/** Stateful MIDI channel class.
|
|
|
|
*
|
|
|
|
* This remembers various useful information about the current 'state' of a
|
|
|
|
* MIDI channel (eg current pitch bend value).
|
|
|
|
*/
|
2013-10-17 10:27:04 -04:00
|
|
|
class LIBMIDIPP_API Channel : public PBD::ScopedConnectionList {
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
public:
|
2012-04-23 22:28:51 -04:00
|
|
|
Channel (byte channel_number, Port &);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
Port &midi_port() { return _port; }
|
2008-06-02 17:41:35 -04:00
|
|
|
byte channel() { return _channel_number; }
|
|
|
|
byte program() { return _program_number; }
|
2014-04-28 19:58:24 -04:00
|
|
|
unsigned short bank() { return _bank_number; }
|
2008-06-02 17:41:35 -04:00
|
|
|
byte pressure () { return _chanpress; }
|
|
|
|
byte poly_pressure (byte n) { return _polypress[n]; }
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
byte last_note_on () {
|
2008-06-02 17:41:35 -04:00
|
|
|
return _last_note_on;
|
|
|
|
}
|
2015-10-04 14:51:05 -04:00
|
|
|
byte last_on_velocity () {
|
2008-06-02 17:41:35 -04:00
|
|
|
return _last_on_velocity;
|
|
|
|
}
|
2015-10-04 14:51:05 -04:00
|
|
|
byte last_note_off () {
|
2008-06-02 17:41:35 -04:00
|
|
|
return _last_note_off;
|
|
|
|
}
|
2015-10-04 14:51:05 -04:00
|
|
|
byte last_off_velocity () {
|
2008-06-02 17:41:35 -04:00
|
|
|
return _last_off_velocity;
|
|
|
|
}
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
pitchbend_t pitchbend () {
|
2008-06-02 17:41:35 -04:00
|
|
|
return _pitch_bend;
|
|
|
|
}
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
controller_value_t controller_value (byte n) {
|
2008-06-02 17:41:35 -04:00
|
|
|
return _controller_val[n%128];
|
|
|
|
}
|
|
|
|
|
|
|
|
controller_value_t *controller_addr (byte n) {
|
|
|
|
return &_controller_val[n%128];
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_controller (byte n, byte val) {
|
|
|
|
_controller_val[n%128] = val;
|
|
|
|
}
|
|
|
|
|
2015-11-23 10:44:40 -05:00
|
|
|
controller_value_t rpn_value (uint16_t rpn_id);
|
|
|
|
controller_value_t nrpn_value (uint16_t rpn_id);
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
bool channel_msg (byte id, byte val1, byte val2, timestamp_t timestamp);
|
|
|
|
bool all_notes_off (timestamp_t timestamp) {
|
|
|
|
return channel_msg (MIDI::controller, 123, 0, timestamp);
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
bool control (byte id, byte value, timestamp_t timestamp) {
|
|
|
|
return channel_msg (MIDI::controller, id, value, timestamp);
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
bool note_on (byte note, byte velocity, timestamp_t timestamp) {
|
|
|
|
return channel_msg (MIDI::on, note, velocity, timestamp);
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
bool note_off (byte note, byte velocity, timestamp_t timestamp) {
|
|
|
|
return channel_msg (MIDI::off, note, velocity, timestamp);
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
bool aftertouch (byte value, timestamp_t timestamp) {
|
|
|
|
return channel_msg (MIDI::chanpress, value, 0, timestamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool poly_aftertouch (byte note, byte value, timestamp_t timestamp) {
|
|
|
|
return channel_msg (MIDI::polypress, note, value, timestamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool program_change (byte value, timestamp_t timestamp) {
|
|
|
|
return channel_msg (MIDI::program, value, 0, timestamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool pitchbend (byte msb, byte lsb, timestamp_t timestamp) {
|
|
|
|
return channel_msg (MIDI::pitchbend, lsb, msb, timestamp);
|
|
|
|
}
|
|
|
|
|
2015-11-23 10:44:40 -05:00
|
|
|
float rpn_value (uint16_t rpn) const;
|
|
|
|
float nrpn_value (uint16_t nrpn) const;
|
|
|
|
float rpn_value_absolute (uint16_t rpn) const;
|
|
|
|
float nrpn_value_absolute (uint16_t nrpn) const;
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
protected:
|
2012-04-23 22:28:51 -04:00
|
|
|
friend class Port;
|
2010-07-07 21:00:46 -04:00
|
|
|
void connect_signals ();
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
private:
|
2012-04-23 22:28:51 -04:00
|
|
|
Port& _port;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2015-11-23 10:44:40 -05:00
|
|
|
enum RPNState {
|
|
|
|
HaveLSB = 0x1,
|
|
|
|
HaveMSB = 0x2,
|
|
|
|
HaveValue = 0x4
|
|
|
|
};
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
/* Current channel values */
|
|
|
|
byte _channel_number;
|
2014-04-28 19:58:24 -04:00
|
|
|
unsigned short _bank_number;
|
2008-06-02 17:41:35 -04:00
|
|
|
byte _program_number;
|
|
|
|
byte _rpn_msb;
|
|
|
|
byte _rpn_lsb;
|
2015-11-23 10:44:40 -05:00
|
|
|
byte _rpn_val_msb;
|
|
|
|
byte _rpn_val_lsb;
|
2008-06-02 17:41:35 -04:00
|
|
|
byte _nrpn_msb;
|
|
|
|
byte _nrpn_lsb;
|
2015-11-23 10:44:40 -05:00
|
|
|
byte _nrpn_val_lsb;
|
|
|
|
byte _nrpn_val_msb;
|
|
|
|
RPNState _rpn_state;
|
|
|
|
RPNState _nrpn_state;
|
2008-06-02 17:41:35 -04:00
|
|
|
byte _chanpress;
|
|
|
|
byte _polypress[128];
|
|
|
|
bool _controller_14bit[128];
|
|
|
|
controller_value_t _controller_val[128];
|
|
|
|
byte _controller_msb[128];
|
|
|
|
byte _controller_lsb[128];
|
|
|
|
byte _last_note_on;
|
|
|
|
byte _last_on_velocity;
|
|
|
|
byte _last_note_off;
|
|
|
|
byte _last_off_velocity;
|
|
|
|
pitchbend_t _pitch_bend;
|
|
|
|
bool _omni;
|
|
|
|
bool _poly;
|
|
|
|
bool _mono;
|
|
|
|
size_t _notes_on;
|
|
|
|
|
2015-11-23 10:44:40 -05:00
|
|
|
typedef std::map<uint16_t,float> RPNList;
|
|
|
|
|
|
|
|
RPNList rpns;
|
|
|
|
RPNList nrpns;
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
void reset (timestamp_t timestamp, samplecnt_t nframes, bool notes_off = true);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
void process_note_off (Parser &, EventTwoBytes *);
|
|
|
|
void process_note_on (Parser &, EventTwoBytes *);
|
|
|
|
void process_controller (Parser &, EventTwoBytes *);
|
|
|
|
void process_polypress (Parser &, EventTwoBytes *);
|
|
|
|
void process_program_change (Parser &, byte);
|
|
|
|
void process_chanpress (Parser &, byte);
|
|
|
|
void process_pitchbend (Parser &, pitchbend_t);
|
|
|
|
void process_reset (Parser &);
|
2015-11-23 10:44:40 -05:00
|
|
|
bool maybe_process_rpns (Parser&, EventTwoBytes *);
|
|
|
|
|
|
|
|
void rpn_reset ();
|
|
|
|
void nrpn_reset ();
|
|
|
|
|
|
|
|
static const RPNState RPN_READY_FOR_VALUE;
|
|
|
|
static const RPNState RPN_VALUE_READY;
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace MIDI
|
|
|
|
|
|
|
|
#endif // __midichannel_h__
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|