tcp: Fix 64 bit build with debugging features enabled.
[haiku.git] / src / kits / midi / Synth.cpp
blob7777d1cab77da19e29f62894bcbefee11f0498e4
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.
8 * Authors:
9 * Jérôme Leveque
10 * Matthijs Hollemans
13 #include <string.h>
15 #include "debug.h"
16 #include <Path.h>
17 #include <Synth.h>
18 #include "SoftSynth.h"
20 BSynth* be_synth = NULL;
22 using namespace BPrivate;
25 BSynth::BSynth()
27 _Init();
31 BSynth::BSynth(synth_mode mode)
33 _Init();
34 fSynthMode = mode;
38 BSynth::~BSynth()
40 delete fSynth;
41 be_synth = NULL;
45 status_t
46 BSynth::LoadSynthData(entry_ref* instrumentsFile)
48 if (instrumentsFile == NULL) {
49 return B_BAD_VALUE;
52 BPath path(instrumentsFile);
53 status_t err = path.InitCheck();
54 if (err != B_OK)
55 return err;
56 return fSynth->SetInstrumentsFile(path.Path());
60 status_t
61 BSynth::LoadSynthData(synth_mode mode)
63 // Our softsynth doesn't support multiple modes like Be's synth did.
64 // Therefore, if you use this function, the synth will revert to its
65 // default instruments bank. However, we do keep track of the current
66 // synth_mode here, in order not to confuse old applications.
68 fSynthMode = mode;
69 if (fSynthMode == B_SAMPLES_ONLY) {
70 fprintf(stderr, "[midi] LoadSynthData: BSamples is not supported\n");
73 return fSynth->SetDefaultInstrumentsFile();
77 synth_mode
78 BSynth::SynthMode()
80 return fSynthMode;
84 void
85 BSynth::Unload()
87 fSynth->Unload();
91 bool
92 BSynth::IsLoaded() const
94 return fSynth->IsLoaded();
98 status_t
99 BSynth::SetSamplingRate(int32 sample_rate)
101 return fSynth->SetSamplingRate(sample_rate);
105 int32
106 BSynth::SamplingRate() const
108 return fSynth->SamplingRate();
112 status_t
113 BSynth::SetInterpolation(interpolation_mode interp_mode)
115 return fSynth->SetInterpolation(interp_mode);
119 interpolation_mode
120 BSynth::Interpolation() const
122 return fSynth->Interpolation();
126 void
127 BSynth::SetReverb(reverb_mode rev_mode)
129 fSynth->SetReverb(rev_mode);
133 reverb_mode
134 BSynth::Reverb() const
136 return fSynth->Reverb();
140 status_t
141 BSynth::EnableReverb(bool reverb_enabled)
143 return fSynth->EnableReverb(reverb_enabled);
147 bool
148 BSynth::IsReverbEnabled() const
150 return fSynth->IsReverbEnabled();
154 status_t
155 BSynth::SetVoiceLimits(
156 int16 maxSynthVoices, int16 maxSampleVoices, int16 limiterThreshhold)
158 status_t err = B_OK;
159 err = fSynth->SetMaxVoices(maxSynthVoices);
160 if (err == B_OK) {
161 err = fSynth->SetLimiterThreshold(limiterThreshhold);
163 return err;
167 int16
168 BSynth::MaxSynthVoices() const
170 return fSynth->MaxVoices();
174 int16
175 BSynth::MaxSampleVoices() const
177 fprintf(stderr, "[midi] MaxSampleVoices: BSamples not supported\n");
178 return 0;
182 int16
183 BSynth::LimiterThreshhold() const
185 return fSynth->LimiterThreshold();
189 void
190 BSynth::SetSynthVolume(double theVolume)
192 fSynth->SetVolume(theVolume);
196 double
197 BSynth::SynthVolume() const
199 return fSynth->Volume();
203 void
204 BSynth::SetSampleVolume(double theVolume)
206 fprintf(stderr, "[midi] SetSampleVolume: BSamples not supported\n");
210 double
211 BSynth::SampleVolume(void) const
213 fprintf(stderr, "[midi] SampleVolume: BSamples not supported\n");
214 return 0;
218 status_t
219 BSynth::GetAudio(int16* pLeft, int16* pRight, int32 max_samples) const
221 // We don't print a "not supported" message here. That would cause
222 // significant slowdowns because applications ask for this many times.
224 if (fSynth->fMonitorSize <= 0) {
225 memset(pLeft, 0, max_samples * sizeof(int16));
226 memset(pRight, 0, max_samples * sizeof(int16));
227 return max_samples;
230 int32 nSamples = fSynth->fMonitorSize / sizeof(float)
231 / fSynth->fMonitorChans;
232 if (nSamples > max_samples)
233 nSamples = max_samples;
234 float* sPtr = fSynth->fMonitor;
235 for (int32 i = 0; i < nSamples; i++, sPtr += fSynth->fMonitorChans) {
236 *pLeft++ = (int16)(*sPtr * 32768);
237 *pRight++ = (int16)(*(sPtr + 1) * 32768);
239 return nSamples;
243 void
244 BSynth::Pause()
246 fSynth->Pause();
250 void
251 BSynth::Resume()
253 fSynth->Resume();
257 void
258 BSynth::SetControllerHook(int16 controller, synth_controller_hook cback)
260 fprintf(stderr, "[midi] SetControllerHook is not supported\n");
264 void
265 BSynth::_Init()
267 delete be_synth;
268 be_synth = this;
269 fSynthMode = B_NO_SYNTH;
270 fClientCount = 0;
271 fSynth = new BSoftSynth();
275 int32
276 BSynth::CountClients() const
278 return fClientCount;
282 void BSynth::_ReservedSynth1() { }
283 void BSynth::_ReservedSynth2() { }
284 void BSynth::_ReservedSynth3() { }
285 void BSynth::_ReservedSynth4() { }