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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 411 - (hide annotations) (download)
Sat Feb 26 02:01:14 2005 UTC (19 years, 2 months ago) by schoenebeck
File size: 8623 byte(s)
* design change: using now one sampler engine instance and one disk thread
  instance for all sampler channels that are connected to the same audio
  output device (and are using the same engine type of course)
* added EngineFactory / EngineChannelFactory to remove the annoying build
  dependencies e.g. of the lscpserver to the actual sampler engine
  implementations
* bumped version to 0.3.0 (current CVS state is still quite broken,
  previous, stable CVS version was tagged as "v0_2_0" and is also available
  as source tarball)

1 schoenebeck 221 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 411 * Copyright (C) 2005 Christian Schoenebeck *
7 schoenebeck 221 * *
8     * This program is free software; you can redistribute it and/or modify *
9     * it under the terms of the GNU General Public License as published by *
10     * the Free Software Foundation; either version 2 of the License, or *
11     * (at your option) any later version. *
12     * *
13     * This program is distributed in the hope that it will be useful, *
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16     * GNU General Public License for more details. *
17     * *
18     * You should have received a copy of the GNU General Public License *
19     * along with this program; if not, write to the Free Software *
20     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21     * MA 02111-1307 USA *
22     ***************************************************************************/
23    
24     #include "MidiInputPort.h"
25    
26     namespace LinuxSampler {
27    
28     // *************** ParameterName ***************
29     // *
30    
31     MidiInputPort::ParameterName::ParameterName(MidiInputPort* pPort) : DeviceRuntimeParameterString("Port " + ToString(pPort->GetPortNumber())) {
32     this->pPort = pPort;
33     }
34    
35     MidiInputPort::ParameterName::ParameterName(MidiInputPort* pPort, String val) : DeviceRuntimeParameterString(val) {
36     this->pPort = pPort;
37     }
38    
39     String MidiInputPort::ParameterName::Description() {
40     return "Name for this port";
41     }
42    
43     bool MidiInputPort::ParameterName::Fix() {
44     return false;
45     }
46    
47     std::vector<String> MidiInputPort::ParameterName::PossibilitiesAsString() {
48     return std::vector<String>();
49     }
50    
51     void MidiInputPort::ParameterName::OnSetValue(String s) throw (LinuxSamplerException) {
52     return; /* FIXME: Nothing to do here */
53     }
54    
55    
56    
57     // *************** MidiInputPort ***************
58     // *
59    
60     MidiInputPort::~MidiInputPort() {
61     std::map<String,DeviceRuntimeParameter*>::iterator iter = Parameters.begin();
62     while (iter != Parameters.end()) {
63     Parameters.erase(iter);
64     delete iter->second;
65     iter++;
66     }
67     }
68    
69     MidiInputPort::MidiInputPort(MidiInputDevice* pDevice, int portNumber) {
70     this->pDevice = pDevice;
71     this->portNumber = portNumber;
72     Parameters["NAME"] = new ParameterName(this);
73     }
74    
75     MidiInputDevice* MidiInputPort::GetDevice() {
76     return pDevice;
77     }
78    
79     uint MidiInputPort::GetPortNumber() {
80     return portNumber;
81     }
82    
83     std::map<String,DeviceRuntimeParameter*> MidiInputPort::PortParameters() {
84     return Parameters;
85     }
86    
87     void MidiInputPort::DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel) {
88 schoenebeck 274 // dispatch event for engines listening to the same MIDI channel
89     {
90 schoenebeck 411 std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();
91     std::set<EngineChannel*>::iterator end = MidiChannelMap[MidiChannel].end();
92 schoenebeck 274 for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOn(Key, Velocity);
93     }
94     // dispatch event for engines listening to ALL MIDI channels
95     {
96 schoenebeck 411 std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[midi_chan_all].begin();
97     std::set<EngineChannel*>::iterator end = MidiChannelMap[midi_chan_all].end();
98 schoenebeck 274 for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOn(Key, Velocity);
99     }
100 schoenebeck 221 }
101    
102     void MidiInputPort::DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel) {
103 schoenebeck 274 // dispatch event for engines listening to the same MIDI channel
104     {
105 schoenebeck 411 std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();
106     std::set<EngineChannel*>::iterator end = MidiChannelMap[MidiChannel].end();
107 schoenebeck 274 for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity);
108     }
109     // dispatch event for engines listening to ALL MIDI channels
110     {
111 schoenebeck 411 std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[midi_chan_all].begin();
112     std::set<EngineChannel*>::iterator end = MidiChannelMap[midi_chan_all].end();
113 schoenebeck 274 for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity);
114     }
115 schoenebeck 221 }
116    
117     void MidiInputPort::DispatchPitchbend(int Pitch, uint MidiChannel) {
118 schoenebeck 274 // dispatch event for engines listening to the same MIDI channel
119     {
120 schoenebeck 411 std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();
121     std::set<EngineChannel*>::iterator end = MidiChannelMap[MidiChannel].end();
122 schoenebeck 274 for (; engineiter != end; engineiter++) (*engineiter)->SendPitchbend(Pitch);
123     }
124     // dispatch event for engines listening to ALL MIDI channels
125     {
126 schoenebeck 411 std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[midi_chan_all].begin();
127     std::set<EngineChannel*>::iterator end = MidiChannelMap[midi_chan_all].end();
128 schoenebeck 274 for (; engineiter != end; engineiter++) (*engineiter)->SendPitchbend(Pitch);
129     }
130 schoenebeck 221 }
131    
132     void MidiInputPort::DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel) {
133 schoenebeck 274 // dispatch event for engines listening to the same MIDI channel
134     {
135 schoenebeck 411 std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();
136     std::set<EngineChannel*>::iterator end = MidiChannelMap[MidiChannel].end();
137 schoenebeck 274 for (; engineiter != end; engineiter++) (*engineiter)->SendControlChange(Controller, Value);
138     }
139     // dispatch event for engines listening to ALL MIDI channels
140     {
141 schoenebeck 411 std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[midi_chan_all].begin();
142     std::set<EngineChannel*>::iterator end = MidiChannelMap[midi_chan_all].end();
143 schoenebeck 274 for (; engineiter != end; engineiter++) (*engineiter)->SendControlChange(Controller, Value);
144     }
145 schoenebeck 221 }
146    
147 schoenebeck 244 void MidiInputPort::DispatchSysex(void* pData, uint Size) {
148 schoenebeck 274 // dispatch event for engines listening to the same MIDI channel
149     {
150     for (uint MidiChannel = 0; MidiChannel <= 16; MidiChannel++) {
151 schoenebeck 411 std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();
152     std::set<EngineChannel*>::iterator end = MidiChannelMap[MidiChannel].end();
153     for (; engineiter != end; engineiter++) {
154     Engine* pEngine = (*engineiter)->GetEngine();
155     if (pEngine) pEngine->SendSysex(pData, Size);
156     }
157 schoenebeck 274 }
158 schoenebeck 244 }
159 schoenebeck 274 // dispatch event for engines listening to ALL MIDI channels
160     {
161     for (uint MidiChannel = 0; MidiChannel <= 16; MidiChannel++) {
162 schoenebeck 411 std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[midi_chan_all].begin();
163     std::set<EngineChannel*>::iterator end = MidiChannelMap[midi_chan_all].end();
164     for (; engineiter != end; engineiter++) {
165     Engine* pEngine = (*engineiter)->GetEngine();
166     if (pEngine) pEngine->SendSysex(pData, Size);
167     }
168 schoenebeck 274 }
169     }
170 schoenebeck 244 }
171    
172 schoenebeck 411 void MidiInputPort::Connect(EngineChannel* pEngineChannel, midi_chan_t MidiChannel) {
173 schoenebeck 221 if (MidiChannel < 0 || MidiChannel > 16)
174     throw MidiInputException("MIDI channel index out of bounds");
175 schoenebeck 411 Disconnect(pEngineChannel);
176     MidiChannelMap[MidiChannel].insert(pEngineChannel);
177 schoenebeck 221 }
178    
179 schoenebeck 411 void MidiInputPort::Disconnect(EngineChannel* pEngineChannel) {
180     try { for (int i = 0; i <= 16; i++) MidiChannelMap[i].erase(pEngineChannel); }
181 schoenebeck 221 catch(...) { /* NOOP */ }
182     }
183    
184     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC