2003-03-17 22:30:19 +00:00
|
|
|
/*
|
2004-05-13 09:44:22 +00:00
|
|
|
* Copyright (c) 2002-2004 Matthijs Hollemans
|
2004-05-13 16:46:06 +00:00
|
|
|
* Copyright (c) 2003 Jerome Leveque
|
2002-11-01 15:07:39 +00:00
|
|
|
*
|
2003-03-17 22:30:19 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
2002-11-01 15:07:39 +00:00
|
|
|
*/
|
|
|
|
|
2004-05-13 19:54:00 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2002-11-01 15:07:39 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "Synth.h"
|
2004-05-13 16:46:06 +00:00
|
|
|
#include "SoftSynth.h"
|
2002-11-01 15:07:39 +00:00
|
|
|
|
2004-05-13 09:18:38 +00:00
|
|
|
BSynth* be_synth = NULL;
|
2003-12-22 23:23:27 +00:00
|
|
|
|
2004-05-13 16:46:06 +00:00
|
|
|
using namespace BPrivate;
|
|
|
|
|
2002-11-01 15:07:39 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BSynth::BSynth()
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
Init();
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2004-05-13 16:46:06 +00:00
|
|
|
BSynth::BSynth(synth_mode mode)
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
Init();
|
|
|
|
synthMode = mode;
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BSynth::~BSynth()
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
delete synth;
|
2004-05-13 09:18:38 +00:00
|
|
|
be_synth = NULL;
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
status_t BSynth::LoadSynthData(entry_ref* instrumentsFile)
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
if (instrumentsFile == NULL)
|
|
|
|
{
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return synth->SetInstrumentsFile(instrumentsFile->name);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2004-05-13 16:46:06 +00:00
|
|
|
status_t BSynth::LoadSynthData(synth_mode mode)
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
// Our softsynth doesn't support multiple modes like Be's synth did.
|
|
|
|
// Therefore, if you use this function, the synth will revert to its
|
|
|
|
// default instruments bank. However, we do keep track of the current
|
|
|
|
// synth_mode here, in order not to confuse old applications.
|
|
|
|
|
|
|
|
synthMode = mode;
|
|
|
|
if (synthMode == B_SAMPLES_ONLY)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "[midi] LoadSynthData: BSamples is not supported\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return synth->SetDefaultInstrumentsFile();
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
synth_mode BSynth::SynthMode(void)
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
return synthMode;
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void BSynth::Unload(void)
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
synth->Unload();
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool BSynth::IsLoaded(void) const
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
return synth->IsLoaded();
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
status_t BSynth::SetSamplingRate(int32 sample_rate)
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
return synth->SetSamplingRate(sample_rate);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
int32 BSynth::SamplingRate() const
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
return synth->SamplingRate();
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
status_t BSynth::SetInterpolation(interpolation_mode interp_mode)
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
return synth->SetInterpolation(interp_mode);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
interpolation_mode BSynth::Interpolation() const
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
return synth->Interpolation();
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void BSynth::SetReverb(reverb_mode rev_mode)
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
synth->SetReverb(rev_mode);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
reverb_mode BSynth::Reverb() const
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
return synth->Reverb();
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
status_t BSynth::EnableReverb(bool reverb_enabled)
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
return synth->EnableReverb(reverb_enabled);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool BSynth::IsReverbEnabled() const
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
return synth->IsReverbEnabled();
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
status_t BSynth::SetVoiceLimits(
|
|
|
|
int16 maxSynthVoices, int16 maxSampleVoices, int16 limiterThreshhold)
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
status_t err = B_OK;
|
|
|
|
err = synth->SetMaxVoices(maxSynthVoices);
|
|
|
|
if (err == B_OK)
|
|
|
|
{
|
|
|
|
err = synth->SetLimiterThreshold(limiterThreshhold);
|
|
|
|
}
|
|
|
|
return err;
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
int16 BSynth::MaxSynthVoices(void) const
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
return synth->MaxVoices();
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
int16 BSynth::MaxSampleVoices(void) const
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
fprintf(stderr, "[midi] MaxSampleVoices: BSamples not supported\n");
|
2002-11-01 15:07:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
int16 BSynth::LimiterThreshhold(void) const
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
return synth->LimiterThreshold();
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void BSynth::SetSynthVolume(double theVolume)
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
synth->SetVolume(theVolume);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
double BSynth::SynthVolume(void) const
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
return synth->Volume();
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void BSynth::SetSampleVolume(double theVolume)
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
fprintf(stderr, "[midi] SetSampleVolume: BSamples not supported\n");
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
double BSynth::SampleVolume(void) const
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
fprintf(stderr, "[midi] SampleVolume: BSamples not supported\n");
|
2002-11-01 15:07:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
status_t BSynth::GetAudio(
|
|
|
|
int16* pLeft, int16* pRight, int32 max_samples) const
|
|
|
|
{
|
2004-05-13 19:54:00 +00:00
|
|
|
// We don't print a "not supported" message here. That would cause
|
|
|
|
// significant slowdowns because applications ask for this many times.
|
|
|
|
|
|
|
|
memset(pLeft, 0, max_samples * sizeof(int16));
|
|
|
|
memset(pRight, 0, max_samples * sizeof(int16));
|
|
|
|
|
|
|
|
return max_samples;
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void BSynth::Pause(void)
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
synth->Pause();
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void BSynth::Resume(void)
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
synth->Resume();
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void BSynth::SetControllerHook(int16 controller, synth_controller_hook cback)
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
fprintf(stderr, "[midi] SetControllerHook is not supported\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void BSynth::Init()
|
|
|
|
{
|
|
|
|
delete be_synth;
|
|
|
|
be_synth = this;
|
|
|
|
synthMode = B_NO_SYNTH;
|
|
|
|
clientCount = 0;
|
|
|
|
synth = new BSoftSynth();
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
int32 BSynth::CountClients(void) const
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
return clientCount;
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void BSynth::_ReservedSynth1() { }
|
|
|
|
void BSynth::_ReservedSynth2() { }
|
|
|
|
void BSynth::_ReservedSynth3() { }
|
|
|
|
void BSynth::_ReservedSynth4() { }
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|