/[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 244 - (hide annotations) (download)
Fri Sep 17 01:01:11 2004 UTC (19 years, 7 months ago) by schoenebeck
File size: 5668 byte(s)
* added support for scale tuning via MIDI GS system exclusive message

1 schoenebeck 221 /***************************************************************************
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     std::set<Engine*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();
88     std::set<Engine*>::iterator end = MidiChannelMap[MidiChannel].end();
89     for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOn(Key, Velocity);
90     }
91    
92     void MidiInputPort::DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel) {
93     std::set<Engine*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();
94     std::set<Engine*>::iterator end = MidiChannelMap[MidiChannel].end();
95     for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity);
96     }
97    
98     void MidiInputPort::DispatchPitchbend(int Pitch, uint MidiChannel) {
99     std::set<Engine*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();
100     std::set<Engine*>::iterator end = MidiChannelMap[MidiChannel].end();
101     for (; engineiter != end; engineiter++) (*engineiter)->SendPitchbend(Pitch);
102     }
103    
104     void MidiInputPort::DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel) {
105     std::set<Engine*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();
106     std::set<Engine*>::iterator end = MidiChannelMap[MidiChannel].end();
107     for (; engineiter != end; engineiter++) (*engineiter)->SendControlChange(Controller, Value);
108     }
109    
110 schoenebeck 244 void MidiInputPort::DispatchSysex(void* pData, uint Size) {
111     for (uint MidiChannel = 0; MidiChannel <= 16; MidiChannel++) {
112     std::set<Engine*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();
113     std::set<Engine*>::iterator end = MidiChannelMap[MidiChannel].end();
114     for (; engineiter != end; engineiter++) (*engineiter)->SendSysex(pData, Size);
115     }
116     }
117    
118 schoenebeck 221 void MidiInputPort::Connect(Engine* pEngine, midi_chan_t MidiChannel) {
119     if (MidiChannel < 0 || MidiChannel > 16)
120     throw MidiInputException("MIDI channel index out of bounds");
121     Disconnect(pEngine);
122     MidiChannelMap[MidiChannel].insert(pEngine);
123     }
124    
125     void MidiInputPort::Disconnect(Engine* pEngine) {
126     try { for (int i = 0; i <= 16; i++) MidiChannelMap[i].erase(pEngine); }
127     catch(...) { /* NOOP */ }
128     }
129    
130     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC