2003-03-17 22:30:19 +00:00
|
|
|
/*
|
2006-07-06 08:56:18 +00:00
|
|
|
* Copyright 2006, Haiku.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2002-2004 Matthijs Hollemans
|
|
|
|
|
* Copyright (c) 2003 Jerome Leveque
|
2006-06-19 13:24:04 +00:00
|
|
|
* Distributed under the terms of the MIT License.
|
2002-11-01 15:07:39 +00:00
|
|
|
*
|
2006-06-19 13:24:04 +00:00
|
|
|
* Authors:
|
|
|
|
|
*
|
|
|
|
|
* Matthijs Hollemans
|
|
|
|
|
* Jérôme Leveque
|
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()
|
|
|
|
|
{
|
2006-06-19 13:24:04 +00:00
|
|
|
if (be_synth == NULL) {
|
2004-05-13 09:44:22 +00:00
|
|
|
new BSynth();
|
|
|
|
|
}
|
2004-05-13 16:46:06 +00:00
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
be_synth->fClientCount++;
|
2004-05-13 16:46:06 +00:00
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
fInputEnabled = false;
|
|
|
|
|
fTranspose = 0;
|
|
|
|
|
fCreationTime = system_time();
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BMidiSynth::~BMidiSynth()
|
|
|
|
|
{
|
2006-06-19 13:24:04 +00:00
|
|
|
be_synth->fClientCount--;
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
status_t
|
|
|
|
|
BMidiSynth::EnableInput(bool enable, bool loadInstruments)
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
status_t err = B_OK;
|
2006-06-19 13:24:04 +00:00
|
|
|
fInputEnabled = enable;
|
2004-05-13 16:46:06 +00:00
|
|
|
|
2006-06-17 14:04:46 +00:00
|
|
|
if (loadInstruments) {
|
2006-06-19 13:24:04 +00:00
|
|
|
err = be_synth->fSynth->LoadAllInstruments();
|
2004-05-13 16:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return err;
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
bool
|
|
|
|
|
BMidiSynth::IsInputEnabled() const
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
2006-06-19 13:24:04 +00:00
|
|
|
return fInputEnabled;
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
void
|
|
|
|
|
BMidiSynth::SetVolume(double volume)
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
2006-06-19 13:24:04 +00:00
|
|
|
be_synth->fSynth->SetVolume(volume);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
double
|
|
|
|
|
BMidiSynth::Volume() const
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
2006-06-19 13:24:04 +00:00
|
|
|
return be_synth->fSynth->Volume();
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
void
|
|
|
|
|
BMidiSynth::SetTransposition(int16 offset)
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
2006-06-19 13:24:04 +00:00
|
|
|
fTranspose = offset;
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
int16
|
|
|
|
|
BMidiSynth::Transposition() const
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
2006-06-19 13:24:04 +00:00
|
|
|
return fTranspose;
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
void
|
|
|
|
|
BMidiSynth::MuteChannel(int16 channel, bool do_mute)
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
void
|
|
|
|
|
BMidiSynth::GetMuteMap(char* pChannels) const
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
void
|
|
|
|
|
BMidiSynth::SoloChannel(int16 channel, bool do_solo)
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
void
|
|
|
|
|
BMidiSynth::GetSoloMap(char* pChannels) const
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
status_t
|
|
|
|
|
BMidiSynth::LoadInstrument(int16 instrument)
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
2006-06-19 13:24:04 +00:00
|
|
|
return be_synth->fSynth->LoadInstrument(instrument);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
status_t
|
|
|
|
|
BMidiSynth::UnloadInstrument(int16 instrument)
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
2006-06-19 13:24:04 +00:00
|
|
|
return be_synth->fSynth->UnloadInstrument(instrument);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
status_t
|
|
|
|
|
BMidiSynth::RemapInstrument(int16 from, int16 to)
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
2006-06-19 13:24:04 +00:00
|
|
|
return be_synth->fSynth->RemapInstrument(from, to);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
void
|
|
|
|
|
BMidiSynth::FlushInstrumentCache(bool startStopCache)
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
2006-06-19 13:24:04 +00:00
|
|
|
be_synth->fSynth->FlushInstrumentCache(startStopCache);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
uint32
|
|
|
|
|
BMidiSynth::Tick() const
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
2006-06-19 13:24:04 +00:00
|
|
|
return (uint32) (system_time() - fCreationTime);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
void
|
|
|
|
|
BMidiSynth::NoteOff(
|
2002-11-01 15:07:39 +00:00
|
|
|
uchar channel, uchar note, uchar velocity, uint32 time)
|
|
|
|
|
{
|
2006-06-19 13:24:04 +00:00
|
|
|
if (fInputEnabled)
|
|
|
|
|
be_synth->fSynth->NoteOff(channel, note + fTranspose, velocity, time);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
void
|
|
|
|
|
BMidiSynth::NoteOn(
|
2002-11-01 15:07:39 +00:00
|
|
|
uchar channel, uchar note, uchar velocity, uint32 time)
|
|
|
|
|
{
|
2006-06-19 13:24:04 +00:00
|
|
|
if (fInputEnabled)
|
|
|
|
|
be_synth->fSynth->NoteOn(channel, note + fTranspose, velocity, time);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
void
|
|
|
|
|
BMidiSynth::KeyPressure(
|
2002-11-01 15:07:39 +00:00
|
|
|
uchar channel, uchar note, uchar pressure, uint32 time)
|
|
|
|
|
{
|
2006-06-19 13:24:04 +00:00
|
|
|
if (fInputEnabled)
|
|
|
|
|
be_synth->fSynth->KeyPressure(
|
|
|
|
|
channel, note + fTranspose, pressure, time);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
void
|
|
|
|
|
BMidiSynth::ControlChange(
|
2002-11-01 15:07:39 +00:00
|
|
|
uchar channel, uchar controlNumber, uchar controlValue, uint32 time)
|
|
|
|
|
{
|
2006-06-19 13:24:04 +00:00
|
|
|
if (fInputEnabled)
|
|
|
|
|
be_synth->fSynth->ControlChange(
|
2004-05-13 16:46:06 +00:00
|
|
|
channel, controlNumber, controlValue, time);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
void
|
|
|
|
|
BMidiSynth::ProgramChange(
|
2002-11-01 15:07:39 +00:00
|
|
|
uchar channel, uchar programNumber, uint32 time)
|
|
|
|
|
{
|
2006-06-19 13:24:04 +00:00
|
|
|
if (fInputEnabled)
|
|
|
|
|
be_synth->fSynth->ProgramChange(channel, programNumber, time);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
void
|
|
|
|
|
BMidiSynth::ChannelPressure(uchar channel, uchar pressure, uint32 time)
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
2006-06-19 13:24:04 +00:00
|
|
|
if (fInputEnabled)
|
|
|
|
|
be_synth->fSynth->ChannelPressure(channel, pressure, time);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
void
|
|
|
|
|
BMidiSynth::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time)
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
2006-06-19 13:24:04 +00:00
|
|
|
if (fInputEnabled)
|
|
|
|
|
be_synth->fSynth->PitchBend(channel, lsb, msb, time);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
void
|
|
|
|
|
BMidiSynth::AllNotesOff(bool justChannel, uint32 time)
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
2006-06-19 13:24:04 +00:00
|
|
|
if (fInputEnabled)
|
|
|
|
|
be_synth->fSynth->AllNotesOff(justChannel, time);
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BMidiSynth::_ReservedMidiSynth1() { }
|
|
|
|
|
void BMidiSynth::_ReservedMidiSynth2() { }
|
|
|
|
|
void BMidiSynth::_ReservedMidiSynth3() { }
|
|
|
|
|
void BMidiSynth::_ReservedMidiSynth4() { }
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 13:24:04 +00:00
|
|
|
void
|
|
|
|
|
BMidiSynth::Run()
|
2002-11-01 15:07:39 +00:00
|
|
|
{
|
2004-05-13 16:46:06 +00:00
|
|
|
// do nothing
|
2002-11-01 15:07:39 +00:00
|
|
|
}
|
|
|
|
|
|