Ardour  8.7-15-gadf511264b
channel.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2006-2009 David Robillard <d@drobilla.net>
4  * Copyright (C) 2010 Carl Hetherington <carl@carlh.net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef __midichannel_h__
22 #define __midichannel_h__
23 
24 #include <queue>
25 #include <map>
26 
27 #include "pbd/signals.h"
28 #include "midi++/parser.h"
29 
30 namespace MIDI {
31 
32 class Port;
33 
40 
41  public:
42  Channel (byte channel_number, Port &);
43 
44  Port &midi_port() { return _port; }
45  byte channel() { return _channel_number; }
46  byte program() { return _program_number; }
47  unsigned short bank() { return _bank_number; }
48  byte pressure () { return _chanpress; }
49  byte poly_pressure (byte n) { return _polypress[n]; }
50 
51  byte last_note_on () {
52  return _last_note_on;
53  }
54  byte last_on_velocity () {
55  return _last_on_velocity;
56  }
57  byte last_note_off () {
58  return _last_note_off;
59  }
61  return _last_off_velocity;
62  }
63 
65  return _pitch_bend;
66  }
67 
69  return _controller_val[n%128];
70  }
71 
73  return &_controller_val[n%128];
74  }
75 
76  void set_controller (byte n, byte val) {
77  _controller_val[n%128] = val;
78  }
79 
80  controller_value_t rpn_value (uint16_t rpn_id);
81  controller_value_t nrpn_value (uint16_t rpn_id);
82 
83  bool channel_msg (byte id, byte val1, byte val2, timestamp_t timestamp);
84  bool all_notes_off (timestamp_t timestamp) {
85  return channel_msg (MIDI::controller, 123, 0, timestamp);
86  }
87 
88  bool control (byte id, byte value, timestamp_t timestamp) {
89  return channel_msg (MIDI::controller, id, value, timestamp);
90  }
91 
92  bool note_on (byte note, byte velocity, timestamp_t timestamp) {
93  return channel_msg (MIDI::on, note, velocity, timestamp);
94  }
95 
96  bool note_off (byte note, byte velocity, timestamp_t timestamp) {
97  return channel_msg (MIDI::off, note, velocity, timestamp);
98  }
99 
100  bool aftertouch (byte value, timestamp_t timestamp) {
101  return channel_msg (MIDI::chanpress, value, 0, timestamp);
102  }
103 
104  bool poly_aftertouch (byte note, byte value, timestamp_t timestamp) {
105  return channel_msg (MIDI::polypress, note, value, timestamp);
106  }
107 
108  bool program_change (byte value, timestamp_t timestamp) {
109  return channel_msg (MIDI::program, value, 0, timestamp);
110  }
111 
112  bool pitchbend (byte msb, byte lsb, timestamp_t timestamp) {
113  return channel_msg (MIDI::pitchbend, lsb, msb, timestamp);
114  }
115 
116  float rpn_value (uint16_t rpn) const;
117  float nrpn_value (uint16_t nrpn) const;
118  float rpn_value_absolute (uint16_t rpn) const;
119  float nrpn_value_absolute (uint16_t nrpn) const;
120 
121  protected:
122  friend class Port;
124 
125  private:
127 
128  enum RPNState {
129  HaveLSB = 0x1,
130  HaveMSB = 0x2,
131  HaveValue = 0x4
132  };
133 
134  /* Current channel values */
136  unsigned short _bank_number;
138  byte _rpn_msb;
139  byte _rpn_lsb;
142  byte _nrpn_msb;
143  byte _nrpn_lsb;
149  byte _polypress[128];
150  bool _controller_14bit[128];
151  controller_value_t _controller_val[128];
152  byte _controller_msb[128];
153  byte _controller_lsb[128];
159  bool _omni;
160  bool _poly;
161  bool _mono;
162  size_t _notes_on;
163 
164  typedef std::map<uint16_t,float> RPNList;
165 
168 
169  void reset (timestamp_t timestamp, samplecnt_t nframes, bool notes_off = true);
170 
176  void process_chanpress (Parser &, byte);
180 
181  void rpn_reset ();
182  void nrpn_reset ();
183 
185  static const RPNState RPN_VALUE_READY;
186 
187 };
188 
189 } // namespace MIDI
190 
191 #endif // __midichannel_h__
192 
193 
194 
195 
bool channel_msg(byte id, byte val1, byte val2, timestamp_t timestamp)
byte _nrpn_val_lsb
Definition: channel.h:144
byte _rpn_msb
Definition: channel.h:138
byte _nrpn_lsb
Definition: channel.h:143
byte program()
Definition: channel.h:46
void reset(timestamp_t timestamp, samplecnt_t nframes, bool notes_off=true)
void process_pitchbend(Parser &, pitchbend_t)
float rpn_value_absolute(uint16_t rpn) const
Port & _port
Definition: channel.h:126
bool _mono
Definition: channel.h:161
byte _chanpress
Definition: channel.h:148
pitchbend_t _pitch_bend
Definition: channel.h:158
void process_note_off(Parser &, EventTwoBytes *)
RPNState _nrpn_state
Definition: channel.h:147
bool _poly
Definition: channel.h:160
controller_value_t controller_value(byte n)
Definition: channel.h:68
byte _last_on_velocity
Definition: channel.h:155
byte _rpn_val_msb
Definition: channel.h:140
bool note_off(byte note, byte velocity, timestamp_t timestamp)
Definition: channel.h:96
byte _last_off_velocity
Definition: channel.h:157
byte channel()
Definition: channel.h:45
void process_reset(Parser &)
void rpn_reset()
RPNList rpns
Definition: channel.h:166
byte _channel_number
Definition: channel.h:135
float nrpn_value_absolute(uint16_t nrpn) const
static const RPNState RPN_VALUE_READY
Definition: channel.h:185
Channel(byte channel_number, Port &)
void nrpn_reset()
controller_value_t nrpn_value(uint16_t rpn_id)
controller_value_t * controller_addr(byte n)
Definition: channel.h:72
void process_polypress(Parser &, EventTwoBytes *)
unsigned short bank()
Definition: channel.h:47
byte _nrpn_msb
Definition: channel.h:142
bool program_change(byte value, timestamp_t timestamp)
Definition: channel.h:108
byte _nrpn_val_msb
Definition: channel.h:145
bool all_notes_off(timestamp_t timestamp)
Definition: channel.h:84
Port & midi_port()
Definition: channel.h:44
void process_chanpress(Parser &, byte)
byte _last_note_off
Definition: channel.h:156
unsigned short _bank_number
Definition: channel.h:136
byte last_note_on()
Definition: channel.h:51
float nrpn_value(uint16_t nrpn) const
bool _omni
Definition: channel.h:159
byte _last_note_on
Definition: channel.h:154
void process_note_on(Parser &, EventTwoBytes *)
bool maybe_process_rpns(Parser &, EventTwoBytes *)
static const RPNState RPN_READY_FOR_VALUE
Definition: channel.h:184
void connect_signals()
bool poly_aftertouch(byte note, byte value, timestamp_t timestamp)
Definition: channel.h:104
byte _rpn_val_lsb
Definition: channel.h:141
byte poly_pressure(byte n)
Definition: channel.h:49
size_t _notes_on
Definition: channel.h:162
byte _program_number
Definition: channel.h:137
void process_program_change(Parser &, byte)
byte last_off_velocity()
Definition: channel.h:60
byte last_on_velocity()
Definition: channel.h:54
RPNState _rpn_state
Definition: channel.h:146
byte _rpn_lsb
Definition: channel.h:139
pitchbend_t pitchbend()
Definition: channel.h:64
bool control(byte id, byte value, timestamp_t timestamp)
Definition: channel.h:88
std::map< uint16_t, float > RPNList
Definition: channel.h:164
float rpn_value(uint16_t rpn) const
controller_value_t rpn_value(uint16_t rpn_id)
bool note_on(byte note, byte velocity, timestamp_t timestamp)
Definition: channel.h:92
bool aftertouch(byte value, timestamp_t timestamp)
Definition: channel.h:100
RPNList nrpns
Definition: channel.h:167
byte pressure()
Definition: channel.h:48
bool pitchbend(byte msb, byte lsb, timestamp_t timestamp)
Definition: channel.h:112
void set_controller(byte n, byte val)
Definition: channel.h:76
void process_controller(Parser &, EventTwoBytes *)
byte last_note_off()
Definition: channel.h:57
#define LIBMIDIPP_API
int64_t samplecnt_t
unsigned short pitchbend_t
float controller_value_t
uint32_t timestamp_t