xref: /haiku/src/kits/midi/MidiSynth.cpp (revision f2b4344867e97c3f4e742a1b4a15e6879644601a)
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 	if (be_synth->fClientCount == 0) {
40 		delete be_synth;
41 		be_synth = NULL;
42 	}
43 }
44 
45 
46 status_t
47 BMidiSynth::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 
60 bool
61 BMidiSynth::IsInputEnabled() const
62 {
63 	return fInputEnabled;
64 }
65 
66 
67 void
68 BMidiSynth::SetVolume(double volume)
69 {
70 	be_synth->fSynth->SetVolume(volume);
71 }
72 
73 
74 double
75 BMidiSynth::Volume() const
76 {
77 	return be_synth->fSynth->Volume();
78 }
79 
80 
81 void
82 BMidiSynth::SetTransposition(int16 offset)
83 {
84 	fTranspose = offset;
85 }
86 
87 
88 int16
89 BMidiSynth::Transposition() const
90 {
91 	return fTranspose;
92 }
93 
94 
95 void
96 BMidiSynth::MuteChannel(int16 channel, bool do_mute)
97 {
98 	fprintf(stderr, "[midi] MuteChannel is broken; don't use it\n");
99 }
100 
101 
102 void
103 BMidiSynth::GetMuteMap(char* pChannels) const
104 {
105 	fprintf(stderr, "[midi] GetMuteMap is broken; don't use it\n");
106 }
107 
108 
109 void
110 BMidiSynth::SoloChannel(int16 channel, bool do_solo)
111 {
112 	fprintf(stderr, "[midi] SoloChannel is broken; don't use it\n");
113 }
114 
115 
116 void
117 BMidiSynth::GetSoloMap(char* pChannels) const
118 {
119 	fprintf(stderr, "[midi] GetSoloMap is broken; don't use it\n");
120 }
121 
122 
123 status_t
124 BMidiSynth::LoadInstrument(int16 instrument)
125 {
126 	return be_synth->fSynth->LoadInstrument(instrument);
127 }
128 
129 
130 status_t
131 BMidiSynth::UnloadInstrument(int16 instrument)
132 {
133 	return be_synth->fSynth->UnloadInstrument(instrument);
134 }
135 
136 
137 status_t
138 BMidiSynth::RemapInstrument(int16 from, int16 to)
139 {
140 	return be_synth->fSynth->RemapInstrument(from, to);
141 }
142 
143 
144 void
145 BMidiSynth::FlushInstrumentCache(bool startStopCache)
146 {
147 	be_synth->fSynth->FlushInstrumentCache(startStopCache);
148 }
149 
150 
151 uint32
152 BMidiSynth::Tick() const
153 {
154 	return (uint32) (system_time() - fCreationTime);
155 }
156 
157 
158 void
159 BMidiSynth::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 
167 void
168 BMidiSynth::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 
176 void
177 BMidiSynth::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 
186 void
187 BMidiSynth::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 
196 void
197 BMidiSynth::ProgramChange(
198 	uchar channel, uchar programNumber, uint32 time)
199 {
200 	if (fInputEnabled)
201 		be_synth->fSynth->ProgramChange(channel, programNumber, time);
202 }
203 
204 
205 void
206 BMidiSynth::ChannelPressure(uchar channel, uchar pressure, uint32 time)
207 {
208 	if (fInputEnabled)
209 		be_synth->fSynth->ChannelPressure(channel, pressure, time);
210 }
211 
212 
213 void
214 BMidiSynth::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 
221 void
222 BMidiSynth::AllNotesOff(bool justChannel, uint32 time)
223 {
224 	if (fInputEnabled)
225 		be_synth->fSynth->AllNotesOff(justChannel, time);
226 }
227 
228 
229 void BMidiSynth::_ReservedMidiSynth1() { }
230 void BMidiSynth::_ReservedMidiSynth2() { }
231 void BMidiSynth::_ReservedMidiSynth3() { }
232 void BMidiSynth::_ReservedMidiSynth4() { }
233 
234 
235 void
236 BMidiSynth::Run()
237 {
238 	// do nothing
239 }
240 
241