1 /* 2 * Copyright (c) 2002-2004 Matthijs Hollemans 3 * Copyright (c) 2003 Jerome Leveque 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 * DEALINGS IN THE SOFTWARE. 22 */ 23 24 #include "debug.h" 25 #include "MidiSynth.h" 26 #include "SoftSynth.h" 27 28 using namespace BPrivate; 29 30 //------------------------------------------------------------------------------ 31 32 BMidiSynth::BMidiSynth() 33 { 34 if (be_synth == NULL) 35 { 36 new BSynth(); 37 } 38 39 be_synth->clientCount++; 40 41 inputEnabled = false; 42 transpose = 0; 43 creationTime = system_time(); 44 } 45 46 //------------------------------------------------------------------------------ 47 48 BMidiSynth::~BMidiSynth() 49 { 50 be_synth->clientCount--; 51 } 52 53 //------------------------------------------------------------------------------ 54 55 status_t BMidiSynth::EnableInput(bool enable, bool loadInstruments) 56 { 57 status_t err = B_OK; 58 inputEnabled = enable; 59 60 if (loadInstruments) 61 { 62 err = be_synth->synth->LoadAllInstruments(); 63 } 64 65 return err; 66 } 67 68 //------------------------------------------------------------------------------ 69 70 bool BMidiSynth::IsInputEnabled(void) const 71 { 72 return inputEnabled; 73 } 74 75 //------------------------------------------------------------------------------ 76 77 void BMidiSynth::SetVolume(double volume) 78 { 79 be_synth->synth->SetVolume(volume); 80 } 81 82 //------------------------------------------------------------------------------ 83 84 double BMidiSynth::Volume(void) const 85 { 86 return be_synth->synth->Volume(); 87 } 88 89 //------------------------------------------------------------------------------ 90 91 void BMidiSynth::SetTransposition(int16 offset) 92 { 93 transpose = offset; 94 } 95 96 //------------------------------------------------------------------------------ 97 98 int16 BMidiSynth::Transposition(void) const 99 { 100 return transpose; 101 } 102 103 //------------------------------------------------------------------------------ 104 105 void BMidiSynth::MuteChannel(int16 channel, bool do_mute) 106 { 107 fprintf(stderr, "[midi] MuteChannel is broken; don't use it\n"); 108 } 109 110 //------------------------------------------------------------------------------ 111 112 void BMidiSynth::GetMuteMap(char* pChannels) const 113 { 114 fprintf(stderr, "[midi] GetMuteMap is broken; don't use it\n"); 115 } 116 117 //------------------------------------------------------------------------------ 118 119 void BMidiSynth::SoloChannel(int16 channel, bool do_solo) 120 { 121 fprintf(stderr, "[midi] SoloChannel is broken; don't use it\n"); 122 } 123 124 //------------------------------------------------------------------------------ 125 126 void BMidiSynth::GetSoloMap(char* pChannels) const 127 { 128 fprintf(stderr, "[midi] GetSoloMap is broken; don't use it\n"); 129 } 130 131 //------------------------------------------------------------------------------ 132 133 status_t BMidiSynth::LoadInstrument(int16 instrument) 134 { 135 return be_synth->synth->LoadInstrument(instrument); 136 } 137 138 //------------------------------------------------------------------------------ 139 140 status_t BMidiSynth::UnloadInstrument(int16 instrument) 141 { 142 return be_synth->synth->UnloadInstrument(instrument); 143 } 144 145 //------------------------------------------------------------------------------ 146 147 status_t BMidiSynth::RemapInstrument(int16 from, int16 to) 148 { 149 return be_synth->synth->RemapInstrument(from, to); 150 } 151 152 //------------------------------------------------------------------------------ 153 154 void BMidiSynth::FlushInstrumentCache(bool startStopCache) 155 { 156 be_synth->synth->FlushInstrumentCache(startStopCache); 157 } 158 159 //------------------------------------------------------------------------------ 160 161 uint32 BMidiSynth::Tick(void) const 162 { 163 return (uint32) (system_time() - creationTime); 164 } 165 166 //------------------------------------------------------------------------------ 167 168 void BMidiSynth::NoteOff( 169 uchar channel, uchar note, uchar velocity, uint32 time) 170 { 171 if (inputEnabled) 172 { 173 be_synth->synth->NoteOff(channel, note + transpose, velocity, time); 174 } 175 } 176 177 //------------------------------------------------------------------------------ 178 179 void BMidiSynth::NoteOn( 180 uchar channel, uchar note, uchar velocity, uint32 time) 181 { 182 if (inputEnabled) 183 { 184 be_synth->synth->NoteOn(channel, note + transpose, velocity, time); 185 } 186 } 187 188 //------------------------------------------------------------------------------ 189 190 void BMidiSynth::KeyPressure( 191 uchar channel, uchar note, uchar pressure, uint32 time) 192 { 193 if (inputEnabled) 194 { 195 be_synth->synth->KeyPressure( 196 channel, note + transpose, pressure, time); 197 } 198 } 199 200 //------------------------------------------------------------------------------ 201 202 void BMidiSynth::ControlChange( 203 uchar channel, uchar controlNumber, uchar controlValue, uint32 time) 204 { 205 if (inputEnabled) 206 { 207 be_synth->synth->ControlChange( 208 channel, controlNumber, controlValue, time); 209 } 210 } 211 212 //------------------------------------------------------------------------------ 213 214 void BMidiSynth::ProgramChange( 215 uchar channel, uchar programNumber, uint32 time) 216 { 217 if (inputEnabled) 218 { 219 be_synth->synth->ProgramChange(channel, programNumber, time); 220 } 221 } 222 223 //------------------------------------------------------------------------------ 224 225 void BMidiSynth::ChannelPressure(uchar channel, uchar pressure, uint32 time) 226 { 227 if (inputEnabled) 228 { 229 be_synth->synth->ChannelPressure(channel, pressure, time); 230 } 231 } 232 233 //------------------------------------------------------------------------------ 234 235 void BMidiSynth::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time) 236 { 237 if (inputEnabled) 238 { 239 be_synth->synth->PitchBend(channel, lsb, msb, time); 240 } 241 } 242 243 //------------------------------------------------------------------------------ 244 245 void BMidiSynth::AllNotesOff(bool justChannel, uint32 time) 246 { 247 if (inputEnabled) 248 { 249 be_synth->synth->AllNotesOff(justChannel, time); 250 } 251 } 252 253 //------------------------------------------------------------------------------ 254 255 void BMidiSynth::_ReservedMidiSynth1() { } 256 void BMidiSynth::_ReservedMidiSynth2() { } 257 void BMidiSynth::_ReservedMidiSynth3() { } 258 void BMidiSynth::_ReservedMidiSynth4() { } 259 260 //------------------------------------------------------------------------------ 261 262 void BMidiSynth::Run() 263 { 264 // do nothing 265 } 266 267 //------------------------------------------------------------------------------ 268