Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
22 
23 #include <queue>
24 #include <map>
25 
26 #include "pbd/signals.h"
27 #include "midi++/parser.h"
28 
29 namespace MIDI {
30 
31 class Port;
32 
39 
40  public:
41  Channel (byte channel_number, Port &);
42 
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]; }
49 
50  byte last_note_on () {
51  return _last_note_on;
52  }
53  byte last_on_velocity () {
54  return _last_on_velocity;
55  }
56  byte last_note_off () {
57  return _last_note_off;
58  }
60  return _last_off_velocity;
61  }
62 
64  return _pitch_bend;
65  }
66 
68  return _controller_val[n%128];
69  }
70 
72  return &_controller_val[n%128];
73  }
74 
75  void set_controller (byte n, byte val) {
76  _controller_val[n%128] = val;
77  }
78 
79  controller_value_t rpn_value (uint16_t rpn_id);
80  controller_value_t nrpn_value (uint16_t rpn_id);
81 
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);
85  }
86 
87  bool control (byte id, byte value, timestamp_t timestamp) {
88  return channel_msg (MIDI::controller, id, value, timestamp);
89  }
90 
91  bool note_on (byte note, byte velocity, timestamp_t timestamp) {
92  return channel_msg (MIDI::on, note, velocity, timestamp);
93  }
94 
95  bool note_off (byte note, byte velocity, timestamp_t timestamp) {
96  return channel_msg (MIDI::off, note, velocity, timestamp);
97  }
98 
99  bool aftertouch (byte value, timestamp_t timestamp) {
100  return channel_msg (MIDI::chanpress, value, 0, timestamp);
101  }
102 
103  bool poly_aftertouch (byte note, byte value, timestamp_t timestamp) {
104  return channel_msg (MIDI::polypress, note, value, timestamp);
105  }
106 
107  bool program_change (byte value, timestamp_t timestamp) {
108  return channel_msg (MIDI::program, value, 0, timestamp);
109  }
110 
111  bool pitchbend (byte msb, byte lsb, timestamp_t timestamp) {
112  return channel_msg (MIDI::pitchbend, lsb, msb, timestamp);
113  }
114 
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;
119 
120  protected:
121  friend class Port;
123 
124  private:
126 
127  enum RPNState {
128  HaveLSB = 0x1,
129  HaveMSB = 0x2,
130  HaveValue = 0x4
131  };
132 
133  /* Current channel values */
135  unsigned short _bank_number;
137  byte _rpn_msb;
138  byte _rpn_lsb;
141  byte _nrpn_msb;
142  byte _nrpn_lsb;
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];
158  bool _omni;
159  bool _poly;
160  bool _mono;
161  size_t _notes_on;
162 
163  typedef std::map<uint16_t,float> RPNList;
164 
167 
168  void reset (timestamp_t timestamp, samplecnt_t nframes, bool notes_off = true);
169 
175  void process_chanpress (Parser &, byte);
179 
180  void rpn_reset ();
181  void nrpn_reset ();
182 
184  static const RPNState RPN_VALUE_READY;
185 
186 };
187 
188 } // namespace MIDI
189 
190 
191 
192 
193 
bool channel_msg(byte id, byte val1, byte val2, timestamp_t timestamp)
byte _nrpn_val_lsb
Definition: channel.h:143
byte _rpn_msb
Definition: channel.h:137
byte _nrpn_lsb
Definition: channel.h:142
byte program()
Definition: channel.h:45
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:125
bool _mono
Definition: channel.h:160
byte _chanpress
Definition: channel.h:147
pitchbend_t _pitch_bend
Definition: channel.h:157
void process_note_off(Parser &, EventTwoBytes *)
RPNState _nrpn_state
Definition: channel.h:146
bool _poly
Definition: channel.h:159
controller_value_t controller_value(byte n)
Definition: channel.h:67
byte _last_on_velocity
Definition: channel.h:154
byte _rpn_val_msb
Definition: channel.h:139
bool note_off(byte note, byte velocity, timestamp_t timestamp)
Definition: channel.h:95
byte _last_off_velocity
Definition: channel.h:156
byte channel()
Definition: channel.h:44
void process_reset(Parser &)
void rpn_reset()
RPNList rpns
Definition: channel.h:165
byte _channel_number
Definition: channel.h:134
float nrpn_value_absolute(uint16_t nrpn) const
static const RPNState RPN_VALUE_READY
Definition: channel.h:184
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:71
void process_polypress(Parser &, EventTwoBytes *)
unsigned short bank()
Definition: channel.h:46
byte _nrpn_msb
Definition: channel.h:141
bool program_change(byte value, timestamp_t timestamp)
Definition: channel.h:107
byte _nrpn_val_msb
Definition: channel.h:144
bool all_notes_off(timestamp_t timestamp)
Definition: channel.h:83
Port & midi_port()
Definition: channel.h:43
void process_chanpress(Parser &, byte)
byte _last_note_off
Definition: channel.h:155
unsigned short _bank_number
Definition: channel.h:135
byte last_note_on()
Definition: channel.h:50
float nrpn_value(uint16_t nrpn) const
bool _omni
Definition: channel.h:158
byte _last_note_on
Definition: channel.h:153
void process_note_on(Parser &, EventTwoBytes *)
bool maybe_process_rpns(Parser &, EventTwoBytes *)
static const RPNState RPN_READY_FOR_VALUE
Definition: channel.h:183
void connect_signals()
bool poly_aftertouch(byte note, byte value, timestamp_t timestamp)
Definition: channel.h:103
byte _rpn_val_lsb
Definition: channel.h:140
byte poly_pressure(byte n)
Definition: channel.h:48
size_t _notes_on
Definition: channel.h:161
byte _program_number
Definition: channel.h:136
void process_program_change(Parser &, byte)
byte last_off_velocity()
Definition: channel.h:59
byte last_on_velocity()
Definition: channel.h:53
RPNState _rpn_state
Definition: channel.h:145
byte _rpn_lsb
Definition: channel.h:138
pitchbend_t pitchbend()
Definition: channel.h:63
bool control(byte id, byte value, timestamp_t timestamp)
Definition: channel.h:87
std::map< uint16_t, float > RPNList
Definition: channel.h:163
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:91
bool aftertouch(byte value, timestamp_t timestamp)
Definition: channel.h:99
RPNList nrpns
Definition: channel.h:166
byte pressure()
Definition: channel.h:47
bool pitchbend(byte msb, byte lsb, timestamp_t timestamp)
Definition: channel.h:111
void set_controller(byte n, byte val)
Definition: channel.h:75
void process_controller(Parser &, EventTwoBytes *)
byte last_note_off()
Definition: channel.h:56
#define LIBMIDIPP_API
int64_t samplecnt_t
unsigned short pitchbend_t
float controller_value_t
uint32_t timestamp_t