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
|
|
|
*/
|
|
|
|
|
|
2005-11-17 22:53:30 +00:00
|
|
|
#include <MidiSynth.h>
|
|
|
|
|
|
2002-11-01 15:07:39 +00:00
|
|
|
#include "debug.h"
|
2004-05-13 16:46:06 +00:00
|
|
|
#include "SoftSynth.h"
|
|
|
|
|
|
|
|
|
|
using namespace BPrivate;
|
2002-11-01 15:07:39 +00:00
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
BMidiSynth::BMidiSynth()
|
|
|
|
|
{
|
2004-05-13 09:44:22 +00:00
|
|
|
if (be_synth == NULL)
|
|
|
|
|
{
|
|
|
|
|
new BSynth();
|
|
|
|
|
}
|
2004-05-13 16:46:06 +00:00
|
|
|
|
|
|
|
|
be_synth->clientCount++;
|
|
|
|
|
|
|
|
|
|
inputEnabled = false;
|
|
|
|
|
transpose = 0;
|
|
|
|
|
creationTime = system_time();
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
BMidiSynth::~BMidiSynth()
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
be_synth->clientCount--;
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
status_t BMidiSynth::EnableInput(bool enable, bool loadInstruments)
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
status_t err = B_OK;
|
|
|
|
|
inputEnabled = enable;
|
|
|
|
|
|
|
|
|
|
if (loadInstruments)
|
|
|
|
|
{
|
|
|
|
|
err = be_synth->synth->LoadAllInstruments();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return err;
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
bool BMidiSynth::IsInputEnabled(void) const
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
return inputEnabled;
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void BMidiSynth::SetVolume(double volume)
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
be_synth->synth->SetVolume(volume);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
double BMidiSynth::Volume(void) const
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
return be_synth->synth->Volume();
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void BMidiSynth::SetTransposition(int16 offset)
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
transpose = offset;
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
int16 BMidiSynth::Transposition(void) const
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
return transpose;
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void BMidiSynth::MuteChannel(int16 channel, bool do_mute)
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
fprintf(stderr, "[midi] MuteChannel is broken; don't use it\n");
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void BMidiSynth::GetMuteMap(char* pChannels) const
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
fprintf(stderr, "[midi] GetMuteMap is broken; don't use it\n");
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void BMidiSynth::SoloChannel(int16 channel, bool do_solo)
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
fprintf(stderr, "[midi] SoloChannel is broken; don't use it\n");
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void BMidiSynth::GetSoloMap(char* pChannels) const
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
fprintf(stderr, "[midi] GetSoloMap is broken; don't use it\n");
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
status_t BMidiSynth::LoadInstrument(int16 instrument)
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
return be_synth->synth->LoadInstrument(instrument);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
status_t BMidiSynth::UnloadInstrument(int16 instrument)
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
return be_synth->synth->UnloadInstrument(instrument);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
status_t BMidiSynth::RemapInstrument(int16 from, int16 to)
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
return be_synth->synth->RemapInstrument(from, to);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void BMidiSynth::FlushInstrumentCache(bool startStopCache)
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
be_synth->synth->FlushInstrumentCache(startStopCache);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
uint32 BMidiSynth::Tick(void) const
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
return (uint32) (system_time() - creationTime);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void BMidiSynth::NoteOff(
|
|
|
|
|
uchar channel, uchar note, uchar velocity, uint32 time)
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
if (inputEnabled)
|
|
|
|
|
{
|
|
|
|
|
be_synth->synth->NoteOff(channel, note + transpose, velocity, time);
|
|
|
|
|
}
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void BMidiSynth::NoteOn(
|
|
|
|
|
uchar channel, uchar note, uchar velocity, uint32 time)
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
if (inputEnabled)
|
|
|
|
|
{
|
|
|
|
|
be_synth->synth->NoteOn(channel, note + transpose, velocity, time);
|
|
|
|
|
}
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void BMidiSynth::KeyPressure(
|
|
|
|
|
uchar channel, uchar note, uchar pressure, uint32 time)
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
if (inputEnabled)
|
|
|
|
|
{
|
|
|
|
|
be_synth->synth->KeyPressure(
|
|
|
|
|
channel, note + transpose, pressure, time);
|
|
|
|
|
}
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void BMidiSynth::ControlChange(
|
|
|
|
|
uchar channel, uchar controlNumber, uchar controlValue, uint32 time)
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
if (inputEnabled)
|
|
|
|
|
{
|
|
|
|
|
be_synth->synth->ControlChange(
|
|
|
|
|
channel, controlNumber, controlValue, time);
|
|
|
|
|
}
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void BMidiSynth::ProgramChange(
|
|
|
|
|
uchar channel, uchar programNumber, uint32 time)
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
if (inputEnabled)
|
|
|
|
|
{
|
|
|
|
|
be_synth->synth->ProgramChange(channel, programNumber, time);
|
|
|
|
|
}
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void BMidiSynth::ChannelPressure(uchar channel, uchar pressure, uint32 time)
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
if (inputEnabled)
|
|
|
|
|
{
|
|
|
|
|
be_synth->synth->ChannelPressure(channel, pressure, time);
|
|
|
|
|
}
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void BMidiSynth::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time)
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
if (inputEnabled)
|
|
|
|
|
{
|
|
|
|
|
be_synth->synth->PitchBend(channel, lsb, msb, time);
|
|
|
|
|
}
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
2004-05-13 16:46:06 +00:00
|
|
|
void BMidiSynth::AllNotesOff(bool justChannel, uint32 time)
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
if (inputEnabled)
|
|
|
|
|
{
|
|
|
|
|
be_synth->synth->AllNotesOff(justChannel, time);
|
|
|
|
|
}
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void BMidiSynth::_ReservedMidiSynth1() { }
|
|
|
|
|
void BMidiSynth::_ReservedMidiSynth2() { }
|
|
|
|
|
void BMidiSynth::_ReservedMidiSynth3() { }
|
|
|
|
|
void BMidiSynth::_ReservedMidiSynth4() { }
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void BMidiSynth::Run()
|
|
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
// do nothing
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|