/[svn]/linuxsampler/trunk/src/drivers/midi/MidiInputPort.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/drivers/midi/MidiInputPort.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 274 - (show annotations) (download)
Sat Oct 9 00:46:18 2004 UTC (19 years, 6 months ago) by schoenebeck
File size: 8131 byte(s)
* MidiInputPort: fixed dispatching of MIDI events to engines which are
  listening to all MIDI channels
* switched MIDI channel indexing to low level indexing (means 0..15 now)

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
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 *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
20 * MA 02111-1307 USA *
21 ***************************************************************************/
22
23 #include "MidiInputPort.h"
24
25 namespace LinuxSampler {
26
27 // *************** ParameterName ***************
28 // *
29
30 MidiInputPort::ParameterName::ParameterName(MidiInputPort* pPort) : DeviceRuntimeParameterString("Port " + ToString(pPort->GetPortNumber())) {
31 this->pPort = pPort;
32 }
33
34 MidiInputPort::ParameterName::ParameterName(MidiInputPort* pPort, String val) : DeviceRuntimeParameterString(val) {
35 this->pPort = pPort;
36 }
37
38 String MidiInputPort::ParameterName::Description() {
39 return "Name for this port";
40 }
41
42 bool MidiInputPort::ParameterName::Fix() {
43 return false;
44 }
45
46 std::vector<String> MidiInputPort::ParameterName::PossibilitiesAsString() {
47 return std::vector<String>();
48 }
49
50 void MidiInputPort::ParameterName::OnSetValue(String s) throw (LinuxSamplerException) {
51 return; /* FIXME: Nothing to do here */
52 }
53
54
55
56 // *************** MidiInputPort ***************
57 // *
58
59 MidiInputPort::~MidiInputPort() {
60 std::map<String,DeviceRuntimeParameter*>::iterator iter = Parameters.begin();
61 while (iter != Parameters.end()) {
62 Parameters.erase(iter);
63 delete iter->second;
64 iter++;
65 }
66 }
67
68 MidiInputPort::MidiInputPort(MidiInputDevice* pDevice, int portNumber) {
69 this->pDevice = pDevice;
70 this->portNumber = portNumber;
71 Parameters["NAME"] = new ParameterName(this);
72 }
73
74 MidiInputDevice* MidiInputPort::GetDevice() {
75 return pDevice;
76 }
77
78 uint MidiInputPort::GetPortNumber() {
79 return portNumber;
80 }
81
82 std::map<String,DeviceRuntimeParameter*> MidiInputPort::PortParameters() {
83 return Parameters;
84 }
85
86 void MidiInputPort::DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel) {
87 // dispatch event for engines listening to the same MIDI channel
88 {
89 std::set<Engine*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();
90 std::set<Engine*>::iterator end = MidiChannelMap[MidiChannel].end();
91 for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOn(Key, Velocity);
92 }
93 // dispatch event for engines listening to ALL MIDI channels
94 {
95 std::set<Engine*>::iterator engineiter = MidiChannelMap[midi_chan_all].begin();
96 std::set<Engine*>::iterator end = MidiChannelMap[midi_chan_all].end();
97 for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOn(Key, Velocity);
98 }
99 }
100
101 void MidiInputPort::DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel) {
102 // dispatch event for engines listening to the same MIDI channel
103 {
104 std::set<Engine*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();
105 std::set<Engine*>::iterator end = MidiChannelMap[MidiChannel].end();
106 for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity);
107 }
108 // dispatch event for engines listening to ALL MIDI channels
109 {
110 std::set<Engine*>::iterator engineiter = MidiChannelMap[midi_chan_all].begin();
111 std::set<Engine*>::iterator end = MidiChannelMap[midi_chan_all].end();
112 for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity);
113 }
114 }
115
116 void MidiInputPort::DispatchPitchbend(int Pitch, uint MidiChannel) {
117 // dispatch event for engines listening to the same MIDI channel
118 {
119 std::set<Engine*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();
120 std::set<Engine*>::iterator end = MidiChannelMap[MidiChannel].end();
121 for (; engineiter != end; engineiter++) (*engineiter)->SendPitchbend(Pitch);
122 }
123 // dispatch event for engines listening to ALL MIDI channels
124 {
125 std::set<Engine*>::iterator engineiter = MidiChannelMap[midi_chan_all].begin();
126 std::set<Engine*>::iterator end = MidiChannelMap[midi_chan_all].end();
127 for (; engineiter != end; engineiter++) (*engineiter)->SendPitchbend(Pitch);
128 }
129 }
130
131 void MidiInputPort::DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel) {
132 // dispatch event for engines listening to the same MIDI channel
133 {
134 std::set<Engine*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();
135 std::set<Engine*>::iterator end = MidiChannelMap[MidiChannel].end();
136 for (; engineiter != end; engineiter++) (*engineiter)->SendControlChange(Controller, Value);
137 }
138 // dispatch event for engines listening to ALL MIDI channels
139 {
140 std::set<Engine*>::iterator engineiter = MidiChannelMap[midi_chan_all].begin();
141 std::set<Engine*>::iterator end = MidiChannelMap[midi_chan_all].end();
142 for (; engineiter != end; engineiter++) (*engineiter)->SendControlChange(Controller, Value);
143 }
144 }
145
146 void MidiInputPort::DispatchSysex(void* pData, uint Size) {
147 // dispatch event for engines listening to the same MIDI channel
148 {
149 for (uint MidiChannel = 0; MidiChannel <= 16; MidiChannel++) {
150 std::set<Engine*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();
151 std::set<Engine*>::iterator end = MidiChannelMap[MidiChannel].end();
152 for (; engineiter != end; engineiter++) (*engineiter)->SendSysex(pData, Size);
153 }
154 }
155 // dispatch event for engines listening to ALL MIDI channels
156 {
157 for (uint MidiChannel = 0; MidiChannel <= 16; MidiChannel++) {
158 std::set<Engine*>::iterator engineiter = MidiChannelMap[midi_chan_all].begin();
159 std::set<Engine*>::iterator end = MidiChannelMap[midi_chan_all].end();
160 for (; engineiter != end; engineiter++) (*engineiter)->SendSysex(pData, Size);
161 }
162 }
163 }
164
165 void MidiInputPort::Connect(Engine* pEngine, midi_chan_t MidiChannel) {
166 if (MidiChannel < 0 || MidiChannel > 16)
167 throw MidiInputException("MIDI channel index out of bounds");
168 Disconnect(pEngine);
169 MidiChannelMap[MidiChannel].insert(pEngine);
170 }
171
172 void MidiInputPort::Disconnect(Engine* pEngine) {
173 try { for (int i = 0; i <= 16; i++) MidiChannelMap[i].erase(pEngine); }
174 catch(...) { /* NOOP */ }
175 }
176
177 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC