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