2 Copyright (C) 1998-99 Paul Barton-Davis
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.
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.
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.
20 #ifndef __midichannel_h__
21 #define __midichannel_h__
26 #include "pbd/signals.h"
27 #include "midi++/parser.h"
33 /** Stateful MIDI channel class.
35 * This remembers various useful information about the current 'state' of a
36 * MIDI channel (eg current pitch bend value).
38 class LIBMIDIPP_API Channel : public PBD::ScopedConnectionList {
41 Channel (byte channel_number, Port &);
43 Port &midi_port() { return _port; }
44 byte channel() { return _channel_number; }
45 byte program() { return _program_number; }
46 unsigned short bank() { return _bank_number; }
47 byte pressure () { return _chanpress; }
48 byte poly_pressure (byte n) { return _polypress[n]; }
50 byte last_note_on () {
53 byte last_on_velocity () {
54 return _last_on_velocity;
56 byte last_note_off () {
57 return _last_note_off;
59 byte last_off_velocity () {
60 return _last_off_velocity;
63 pitchbend_t pitchbend () {
67 controller_value_t controller_value (byte n) {
68 return _controller_val[n%128];
71 controller_value_t *controller_addr (byte n) {
72 return &_controller_val[n%128];
75 void set_controller (byte n, byte val) {
76 _controller_val[n%128] = val;
79 controller_value_t rpn_value (uint16_t rpn_id);
80 controller_value_t nrpn_value (uint16_t rpn_id);
82 bool channel_msg (byte id, byte val1, byte val2, timestamp_t timestamp);
83 bool all_notes_off (timestamp_t timestamp) {
84 return channel_msg (MIDI::controller, 123, 0, timestamp);
87 bool control (byte id, byte value, timestamp_t timestamp) {
88 return channel_msg (MIDI::controller, id, value, timestamp);
91 bool note_on (byte note, byte velocity, timestamp_t timestamp) {
92 return channel_msg (MIDI::on, note, velocity, timestamp);
95 bool note_off (byte note, byte velocity, timestamp_t timestamp) {
96 return channel_msg (MIDI::off, note, velocity, timestamp);
99 bool aftertouch (byte value, timestamp_t timestamp) {
100 return channel_msg (MIDI::chanpress, value, 0, timestamp);
103 bool poly_aftertouch (byte note, byte value, timestamp_t timestamp) {
104 return channel_msg (MIDI::polypress, note, value, timestamp);
107 bool program_change (byte value, timestamp_t timestamp) {
108 return channel_msg (MIDI::program, value, 0, timestamp);
111 bool pitchbend (byte msb, byte lsb, timestamp_t timestamp) {
112 return channel_msg (MIDI::pitchbend, lsb, msb, timestamp);
115 float rpn_value (uint16_t rpn) const;
116 float nrpn_value (uint16_t nrpn) const;
117 float rpn_value_absolute (uint16_t rpn) const;
118 float nrpn_value_absolute (uint16_t nrpn) const;
122 void connect_signals ();
133 /* Current channel values */
134 byte _channel_number;
135 unsigned short _bank_number;
136 byte _program_number;
146 RPNState _nrpn_state;
148 byte _polypress[128];
149 bool _controller_14bit[128];
150 controller_value_t _controller_val[128];
151 byte _controller_msb[128];
152 byte _controller_lsb[128];
154 byte _last_on_velocity;
156 byte _last_off_velocity;
157 pitchbend_t _pitch_bend;
163 typedef std::map<uint16_t,float> RPNList;
168 void reset (timestamp_t timestamp, framecnt_t nframes, bool notes_off = true);
170 void process_note_off (Parser &, EventTwoBytes *);
171 void process_note_on (Parser &, EventTwoBytes *);
172 void process_controller (Parser &, EventTwoBytes *);
173 void process_polypress (Parser &, EventTwoBytes *);
174 void process_program_change (Parser &, byte);
175 void process_chanpress (Parser &, byte);
176 void process_pitchbend (Parser &, pitchbend_t);
177 void process_reset (Parser &);
178 bool maybe_process_rpns (Parser&, EventTwoBytes *);
183 static const RPNState RPN_READY_FOR_VALUE;
184 static const RPNState RPN_VALUE_READY;
190 #endif // __midichannel_h__