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 "MidiStore.h" 26 #include "MidiSynthFile.h" 27 #include "SoftSynth.h" 28 29 using namespace BPrivate; 30 31 // ----------------------------------------------------------------------------- 32 33 BMidiSynthFile::BMidiSynthFile() 34 { 35 store = new BMidiStore(); 36 } 37 38 // ----------------------------------------------------------------------------- 39 40 BMidiSynthFile::~BMidiSynthFile() 41 { 42 Stop(); 43 delete store; 44 } 45 46 // ----------------------------------------------------------------------------- 47 48 status_t BMidiSynthFile::LoadFile(const entry_ref* midi_entry_ref) 49 { 50 if (midi_entry_ref == NULL) 51 { 52 return B_BAD_VALUE; 53 } 54 55 EnableInput(true, false); 56 store->finished = true; 57 58 status_t err = store->Import(midi_entry_ref); 59 60 if (err == B_OK) 61 { 62 for (int t = 0; t < 128; ++t) 63 { 64 if (store->instruments[t]) 65 { 66 be_synth->synth->LoadInstrument(t); 67 } 68 } 69 } 70 71 return err; 72 } 73 74 // ----------------------------------------------------------------------------- 75 76 void BMidiSynthFile::UnloadFile(void) 77 { 78 delete store; 79 store = new BMidiStore(); 80 } 81 82 // ----------------------------------------------------------------------------- 83 84 status_t BMidiSynthFile::Start(void) 85 { 86 store->Connect(this); 87 store->SetCurrentEvent(0); 88 return store->Start(); 89 } 90 91 // ----------------------------------------------------------------------------- 92 93 void BMidiSynthFile::Stop(void) 94 { 95 store->Stop(); 96 store->Disconnect(this); 97 } 98 99 // ----------------------------------------------------------------------------- 100 101 void BMidiSynthFile::Fade(void) 102 { 103 Stop(); // really quick fade :P 104 } 105 106 // ----------------------------------------------------------------------------- 107 108 void BMidiSynthFile::Pause(void) 109 { 110 store->paused = true; 111 } 112 113 // ----------------------------------------------------------------------------- 114 115 void BMidiSynthFile::Resume(void) 116 { 117 store->paused = false; 118 } 119 120 // ----------------------------------------------------------------------------- 121 122 int32 BMidiSynthFile::Duration(void) const 123 { 124 return store->DeltaOfEvent(store->CountEvents()); 125 } 126 127 // ----------------------------------------------------------------------------- 128 129 int32 BMidiSynthFile::Position(int32 ticks) const 130 { 131 return store->EventAtDelta(ticks); 132 } 133 134 // ----------------------------------------------------------------------------- 135 136 int32 BMidiSynthFile::Seek() 137 { 138 return store->CurrentEvent(); 139 } 140 141 // ----------------------------------------------------------------------------- 142 143 status_t BMidiSynthFile::GetPatches( 144 int16* pArray768, int16* pReturnedCount) const 145 { 146 int16 count = 0; 147 148 for (int t = 0; t < 128; ++t) 149 { 150 if (store->instruments[t]) 151 { 152 pArray768[count++] = t; 153 } 154 } 155 156 *pReturnedCount = count; 157 return B_OK; 158 } 159 160 // ----------------------------------------------------------------------------- 161 162 void BMidiSynthFile::SetFileHook(synth_file_hook pSongHook, int32 arg) 163 { 164 store->hookFunc = pSongHook; 165 store->hookArg = arg; 166 } 167 168 // ----------------------------------------------------------------------------- 169 170 bool BMidiSynthFile::IsFinished(void) const 171 { 172 return store->finished; 173 } 174 175 // ----------------------------------------------------------------------------- 176 177 void BMidiSynthFile::ScaleTempoBy(double tempoFactor) 178 { 179 store->SetTempo((int32) (Tempo() * tempoFactor)); 180 } 181 182 // ----------------------------------------------------------------------------- 183 184 void BMidiSynthFile::SetTempo(int32 newTempoBPM) 185 { 186 store->SetTempo(newTempoBPM); 187 } 188 189 // ----------------------------------------------------------------------------- 190 191 int32 BMidiSynthFile::Tempo(void) const 192 { 193 return store->Tempo(); 194 } 195 196 // ----------------------------------------------------------------------------- 197 198 void BMidiSynthFile::EnableLooping(bool loop) 199 { 200 store->looping = loop; 201 } 202 203 // ----------------------------------------------------------------------------- 204 205 void BMidiSynthFile::MuteTrack(int16 track, bool do_mute) 206 { 207 fprintf(stderr, "[midi] MuteTrack is broken; don't use it\n"); 208 } 209 210 // ----------------------------------------------------------------------------- 211 212 void BMidiSynthFile::GetMuteMap(char* pTracks) const 213 { 214 fprintf(stderr, "[midi] GetMuteMap is broken; don't use it\n"); 215 } 216 217 // ----------------------------------------------------------------------------- 218 219 void BMidiSynthFile::SoloTrack(int16 track, bool do_solo) 220 { 221 fprintf(stderr, "[midi] SoloTrack is broken; don't use it\n"); 222 } 223 224 // ----------------------------------------------------------------------------- 225 226 void BMidiSynthFile::GetSoloMap(char* pTracks) const 227 { 228 fprintf(stderr, "[midi] GetSoloMap is broken; don't use it\n"); 229 } 230 231 // ----------------------------------------------------------------------------- 232 233 void BMidiSynthFile::_ReservedMidiSynthFile1() { } 234 void BMidiSynthFile::_ReservedMidiSynthFile2() { } 235 void BMidiSynthFile::_ReservedMidiSynthFile3() { } 236 237 // ----------------------------------------------------------------------------- 238