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 <MidiSynth.h>
15
16#include "debug.h"
17#include "SoftSynth.h"
18
19using namespace BPrivate;
20
21
22BMidiSynth::BMidiSynth()
23{
24	if (be_synth == NULL) {
25		new BSynth();
26	}
27
28	be_synth->fClientCount++;
29
30	fInputEnabled = false;
31	fTranspose = 0;
32	fCreationTime = system_time();
33}
34
35
36BMidiSynth::~BMidiSynth()
37{
38	be_synth->fClientCount--;
39	if (be_synth->fClientCount == 0) {
40		delete be_synth;
41		be_synth = NULL;
42	}
43}
44
45
46status_t
47BMidiSynth::EnableInput(bool enable, bool loadInstruments)
48{
49	status_t err = B_OK;
50	fInputEnabled = enable;
51
52	if (loadInstruments) {
53		err = be_synth->fSynth->LoadAllInstruments();
54	}
55
56	return err;
57}
58
59
60bool
61BMidiSynth::IsInputEnabled() const
62{
63	return fInputEnabled;
64}
65
66
67void
68BMidiSynth::SetVolume(double volume)
69{
70	be_synth->fSynth->SetVolume(volume);
71}
72
73
74double
75BMidiSynth::Volume() const
76{
77	return be_synth->fSynth->Volume();
78}
79
80
81void
82BMidiSynth::SetTransposition(int16 offset)
83{
84	fTranspose = offset;
85}
86
87
88int16
89BMidiSynth::Transposition() const
90{
91	return fTranspose;
92}
93
94
95void
96BMidiSynth::MuteChannel(int16 channel, bool do_mute)
97{
98	fprintf(stderr, "[midi] MuteChannel is broken; don't use it\n");
99}
100
101
102void
103BMidiSynth::GetMuteMap(char* pChannels) const
104{
105	fprintf(stderr, "[midi] GetMuteMap is broken; don't use it\n");
106}
107
108
109void
110BMidiSynth::SoloChannel(int16 channel, bool do_solo)
111{
112	fprintf(stderr, "[midi] SoloChannel is broken; don't use it\n");
113}
114
115
116void
117BMidiSynth::GetSoloMap(char* pChannels) const
118{
119	fprintf(stderr, "[midi] GetSoloMap is broken; don't use it\n");
120}
121
122
123status_t
124BMidiSynth::LoadInstrument(int16 instrument)
125{
126	return be_synth->fSynth->LoadInstrument(instrument);
127}
128
129
130status_t
131BMidiSynth::UnloadInstrument(int16 instrument)
132{
133	return be_synth->fSynth->UnloadInstrument(instrument);
134}
135
136
137status_t
138BMidiSynth::RemapInstrument(int16 from, int16 to)
139{
140	return be_synth->fSynth->RemapInstrument(from, to);
141}
142
143
144void
145BMidiSynth::FlushInstrumentCache(bool startStopCache)
146{
147	be_synth->fSynth->FlushInstrumentCache(startStopCache);
148}
149
150
151uint32
152BMidiSynth::Tick() const
153{
154	return (uint32) (system_time() - fCreationTime);
155}
156
157
158void
159BMidiSynth::NoteOff(
160	uchar channel, uchar note, uchar velocity, uint32 time)
161{
162	if (fInputEnabled)
163		be_synth->fSynth->NoteOff(channel, note + fTranspose, velocity, time);
164}
165
166
167void
168BMidiSynth::NoteOn(
169	uchar channel, uchar note, uchar velocity, uint32 time)
170{
171	if (fInputEnabled)
172		be_synth->fSynth->NoteOn(channel, note + fTranspose, velocity, time);
173}
174
175
176void
177BMidiSynth::KeyPressure(
178	uchar channel, uchar note, uchar pressure, uint32 time)
179{
180	if (fInputEnabled)
181		be_synth->fSynth->KeyPressure(
182			channel, note + fTranspose, pressure, time);
183}
184
185
186void
187BMidiSynth::ControlChange(
188	uchar channel, uchar controlNumber, uchar controlValue, uint32 time)
189{
190	if (fInputEnabled)
191		be_synth->fSynth->ControlChange(
192			channel, controlNumber, controlValue, time);
193}
194
195
196void
197BMidiSynth::ProgramChange(
198	uchar channel, uchar programNumber, uint32 time)
199{
200	if (fInputEnabled)
201		be_synth->fSynth->ProgramChange(channel, programNumber, time);
202}
203
204
205void
206BMidiSynth::ChannelPressure(uchar channel, uchar pressure, uint32 time)
207{
208	if (fInputEnabled)
209		be_synth->fSynth->ChannelPressure(channel, pressure, time);
210}
211
212
213void
214BMidiSynth::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time)
215{
216	if (fInputEnabled)
217		be_synth->fSynth->PitchBend(channel, lsb, msb, time);
218}
219
220
221void
222BMidiSynth::AllNotesOff(bool justChannel, uint32 time)
223{
224	if (fInputEnabled)
225		be_synth->fSynth->AllNotesOff(justChannel, time);
226}
227
228
229void BMidiSynth::_ReservedMidiSynth1() { }
230void BMidiSynth::_ReservedMidiSynth2() { }
231void BMidiSynth::_ReservedMidiSynth3() { }
232void BMidiSynth::_ReservedMidiSynth4() { }
233
234
235void
236BMidiSynth::Run()
237{
238	// do nothing
239}
240
241