Instruments (patches) are now correctly recognized.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7573 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
mahlzeit 2004-05-14 07:46:19 +00:00
parent a808adb023
commit f9b2179cb2
3 changed files with 37 additions and 7 deletions

View File

@ -121,13 +121,14 @@ private:
uint16 _reserved1[1];
bool* instruments;
synth_file_hook hookFunc;
int32 hookArg;
bool looping;
bool paused;
bool finished;
uint32 _reserved2[13];
uint32 _reserved2[12];
};
#endif // _MIDI_STORE_H

View File

@ -84,6 +84,7 @@ BMidiStore::BMidiStore()
looping = false;
paused = false;
finished = false;
instruments = new bool[128];
}
//------------------------------------------------------------------------------
@ -95,6 +96,7 @@ BMidiStore::~BMidiStore()
delete EventAt(t);
}
delete events;
delete[] instruments;
}
//------------------------------------------------------------------------------
@ -248,6 +250,8 @@ void BMidiStore::TempoChange(int32 beatsPerMinute, uint32 time)
status_t BMidiStore::Import(const entry_ref* ref)
{
memset(instruments, 0, 128 * sizeof(bool));
try
{
file = new BFile(ref, B_READ_ONLY);
@ -861,6 +865,11 @@ void BMidiStore::ReadTrack()
event->byte1 = status;
event->byte2 = data1;
AddEvent(event);
if ((status & 0xF0) == B_PROGRAM_CHANGE)
{
instruments[data1] = true;
}
break;
case 0xF0:

View File

@ -24,6 +24,9 @@
#include "debug.h"
#include "MidiStore.h"
#include "MidiSynthFile.h"
#include "SoftSynth.h"
using namespace BPrivate;
// -----------------------------------------------------------------------------
@ -52,10 +55,20 @@ status_t BMidiSynthFile::LoadFile(const entry_ref* midi_entry_ref)
EnableInput(true, false);
store->finished = true;
// TODO: figure out which instruments are used by the MIDI file,
// and load them one-by-one (add a method in BMidiStore for this).
status_t err = store->Import(midi_entry_ref);
return store->Import(midi_entry_ref);
if (err == B_OK)
{
for (int t = 0; t < 128; ++t)
{
if (store->instruments[t])
{
be_synth->synth->LoadInstrument(t);
}
}
}
return err;
}
// -----------------------------------------------------------------------------
@ -130,10 +143,17 @@ int32 BMidiSynthFile::Seek()
status_t BMidiSynthFile::GetPatches(
int16* pArray768, int16* pReturnedCount) const
{
// TODO: when loading of instruments in LoadFile() has been
// implemented, we can finish this function too.
int16 count = 0;
for (int t = 0; t < 128; ++t)
{
if (store->instruments[t])
{
pArray768[count++] = t;
}
}
*pReturnedCount = 0;
*pReturnedCount = count;
return B_OK;
}