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
+2 -1
View File
@@ -121,13 +121,14 @@ private:
uint16 _reserved1[1]; uint16 _reserved1[1];
bool* instruments;
synth_file_hook hookFunc; synth_file_hook hookFunc;
int32 hookArg; int32 hookArg;
bool looping; bool looping;
bool paused; bool paused;
bool finished; bool finished;
uint32 _reserved2[13]; uint32 _reserved2[12];
}; };
#endif // _MIDI_STORE_H #endif // _MIDI_STORE_H
+9
View File
@@ -84,6 +84,7 @@ BMidiStore::BMidiStore()
looping = false; looping = false;
paused = false; paused = false;
finished = false; finished = false;
instruments = new bool[128];
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -95,6 +96,7 @@ BMidiStore::~BMidiStore()
delete EventAt(t); delete EventAt(t);
} }
delete events; delete events;
delete[] instruments;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -248,6 +250,8 @@ void BMidiStore::TempoChange(int32 beatsPerMinute, uint32 time)
status_t BMidiStore::Import(const entry_ref* ref) status_t BMidiStore::Import(const entry_ref* ref)
{ {
memset(instruments, 0, 128 * sizeof(bool));
try try
{ {
file = new BFile(ref, B_READ_ONLY); file = new BFile(ref, B_READ_ONLY);
@@ -861,6 +865,11 @@ void BMidiStore::ReadTrack()
event->byte1 = status; event->byte1 = status;
event->byte2 = data1; event->byte2 = data1;
AddEvent(event); AddEvent(event);
if ((status & 0xF0) == B_PROGRAM_CHANGE)
{
instruments[data1] = true;
}
break; break;
case 0xF0: case 0xF0:
+26 -6
View File
@@ -24,6 +24,9 @@
#include "debug.h" #include "debug.h"
#include "MidiStore.h" #include "MidiStore.h"
#include "MidiSynthFile.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); EnableInput(true, false);
store->finished = true; store->finished = true;
// TODO: figure out which instruments are used by the MIDI file, status_t err = store->Import(midi_entry_ref);
// and load them one-by-one (add a method in BMidiStore for this).
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( status_t BMidiSynthFile::GetPatches(
int16* pArray768, int16* pReturnedCount) const int16* pArray768, int16* pReturnedCount) const
{ {
// TODO: when loading of instruments in LoadFile() has been int16 count = 0;
// implemented, we can finish this function too.
*pReturnedCount = 0; for (int t = 0; t < 128; ++t)
{
if (store->instruments[t])
{
pArray768[count++] = t;
}
}
*pReturnedCount = count;
return B_OK; return B_OK;
} }