1 /*
2 * Copyright 2006, Haiku.
3 *
4 * Copyright (c) 2002-2004 Matthijs Hollemans
5 * Copyright (c) 2003 Jerome Leveque
6 * Distributed under the terms of the MIT License.
7 *
8 * Authors:
9 *
10 * Matthijs Hollemans
11 * Jérôme Leveque
12 */
13
14 #include "debug.h"
15 #include <MidiStore.h>
16 #include <MidiSynthFile.h>
17 #include "SoftSynth.h"
18
19 using namespace BPrivate;
20
21
BMidiSynthFile()22 BMidiSynthFile::BMidiSynthFile()
23 {
24 fStore = new BMidiStore();
25 }
26
27
~BMidiSynthFile()28 BMidiSynthFile::~BMidiSynthFile()
29 {
30 Stop();
31 delete fStore;
32 }
33
34
35 status_t
LoadFile(const entry_ref * midi_entry_ref)36 BMidiSynthFile::LoadFile(const entry_ref* midi_entry_ref)
37 {
38 if (midi_entry_ref == NULL)
39 return B_BAD_VALUE;
40
41 EnableInput(true, false);
42 fStore->fFinished = true;
43
44 status_t err = fStore->Import(midi_entry_ref);
45
46 if (err == B_OK) {
47 for (int t = 0; t < 128; ++t) {
48 if (fStore->fInstruments[t]) {
49 be_synth->fSynth->LoadInstrument(t);
50 }
51 }
52 }
53
54 return err;
55 }
56
57
58 void
UnloadFile(void)59 BMidiSynthFile::UnloadFile(void)
60 {
61 delete fStore;
62 fStore = new BMidiStore();
63 }
64
65
66 status_t
Start(void)67 BMidiSynthFile::Start(void)
68 {
69 fStore->Connect(this);
70 fStore->SetCurrentEvent(0);
71 return fStore->Start();
72 }
73
74
75 void
Stop(void)76 BMidiSynthFile::Stop(void)
77 {
78 fStore->Stop();
79 fStore->Disconnect(this);
80 }
81
82
83 void
Fade(void)84 BMidiSynthFile::Fade(void)
85 {
86 Stop(); // really quick fade :P
87 }
88
89
90 void
Pause(void)91 BMidiSynthFile::Pause(void)
92 {
93 fStore->fPaused = true;
94 }
95
96
97 void
Resume(void)98 BMidiSynthFile::Resume(void)
99 {
100 fStore->fPaused = false;
101 }
102
103
104 int32
Duration(void) const105 BMidiSynthFile::Duration(void) const
106 {
107 return fStore->DeltaOfEvent(fStore->CountEvents());
108 }
109
110
111 int32
Position(int32 ticks) const112 BMidiSynthFile::Position(int32 ticks) const
113 {
114 return fStore->EventAtDelta(ticks);
115 }
116
117
118 int32
Seek()119 BMidiSynthFile::Seek()
120 {
121 return fStore->CurrentEvent();
122 }
123
124
125 status_t
GetPatches(int16 * pArray768,int16 * pReturnedCount) const126 BMidiSynthFile::GetPatches(
127 int16* pArray768, int16* pReturnedCount) const
128 {
129 int16 count = 0;
130
131 for (int t = 0; t < 128; ++t) {
132 if (fStore->fInstruments[t]) {
133 pArray768[count++] = t;
134 }
135 }
136
137 *pReturnedCount = count;
138 return B_OK;
139 }
140
141
142 void
SetFileHook(synth_file_hook pSongHook,int32 arg)143 BMidiSynthFile::SetFileHook(synth_file_hook pSongHook, int32 arg)
144 {
145 fStore->fHookFunc = pSongHook;
146 fStore->fHookArg = arg;
147 }
148
149
150 bool
IsFinished() const151 BMidiSynthFile::IsFinished() const
152 {
153 return fStore->fFinished;
154 }
155
156
157 void
ScaleTempoBy(double tempoFactor)158 BMidiSynthFile::ScaleTempoBy(double tempoFactor)
159 {
160 fStore->SetTempo((int32) (Tempo() * tempoFactor));
161 }
162
163
164 void
SetTempo(int32 newTempoBPM)165 BMidiSynthFile::SetTempo(int32 newTempoBPM)
166 {
167 fStore->SetTempo(newTempoBPM);
168 }
169
170
171 int32
Tempo(void) const172 BMidiSynthFile::Tempo(void) const
173 {
174 return fStore->Tempo();
175 }
176
177
178 void
EnableLooping(bool loop)179 BMidiSynthFile::EnableLooping(bool loop)
180 {
181 fStore->fLooping = loop;
182 }
183
184
185 void
MuteTrack(int16 track,bool do_mute)186 BMidiSynthFile::MuteTrack(int16 track, bool do_mute)
187 {
188 fprintf(stderr, "[midi] MuteTrack is broken; don't use it\n");
189 }
190
191
192 void
GetMuteMap(char * pTracks) const193 BMidiSynthFile::GetMuteMap(char* pTracks) const
194 {
195 fprintf(stderr, "[midi] GetMuteMap is broken; don't use it\n");
196 }
197
198
199 void
SoloTrack(int16 track,bool do_solo)200 BMidiSynthFile::SoloTrack(int16 track, bool do_solo)
201 {
202 fprintf(stderr, "[midi] SoloTrack is broken; don't use it\n");
203 }
204
205
206 void
GetSoloMap(char * pTracks) const207 BMidiSynthFile::GetSoloMap(char* pTracks) const
208 {
209 fprintf(stderr, "[midi] GetSoloMap is broken; don't use it\n");
210 }
211
212
_ReservedMidiSynthFile1()213 void BMidiSynthFile::_ReservedMidiSynthFile1() { }
_ReservedMidiSynthFile2()214 void BMidiSynthFile::_ReservedMidiSynthFile2() { }
_ReservedMidiSynthFile3()215 void BMidiSynthFile::_ReservedMidiSynthFile3() { }
216
217