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