2008-03-05 03:10:31 +00:00
|
|
|
/*
|
|
|
|
** music_midi_midiout.cpp
|
2010-09-02 23:17:58 +00:00
|
|
|
** Code to let ZDoom play HMI MIDI music through the MIDI streaming API.
|
2008-03-05 03:10:31 +00:00
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
2010-09-02 23:17:58 +00:00
|
|
|
** Copyright 2010 Randy Heit
|
2008-03-05 03:10:31 +00:00
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
// HEADER FILES ------------------------------------------------------------
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
#include "i_musicinterns.h"
|
|
|
|
#include "templates.h"
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "m_swap.h"
|
|
|
|
|
2008-03-05 03:10:31 +00:00
|
|
|
// MACROS ------------------------------------------------------------------
|
|
|
|
|
2010-09-23 22:37:25 +00:00
|
|
|
#define SONG_MAGIC "HMI-MIDISONG061595"
|
2010-09-02 23:17:58 +00:00
|
|
|
#define TRACK_MAGIC "HMI-MIDITRACK"
|
|
|
|
|
2008-03-05 03:10:31 +00:00
|
|
|
// Used by SendCommand to check for unexpected end-of-track conditions.
|
|
|
|
#define CHECK_FINISHED \
|
|
|
|
if (track->TrackP >= track->MaxTrackP) \
|
|
|
|
{ \
|
|
|
|
track->Finished = true; \
|
|
|
|
return events; \
|
|
|
|
}
|
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
// In song header
|
2010-09-23 22:37:25 +00:00
|
|
|
#define DIVISION_OFFSET 0xD2
|
2010-09-02 23:17:58 +00:00
|
|
|
#define TRACK_COUNT_OFFSET 0xE4
|
|
|
|
#define TRACK_DIR_PTR_OFFSET 0xE8
|
|
|
|
|
|
|
|
// In track header
|
|
|
|
#define TRACK_DATA_PTR_OFFSET 0x57
|
|
|
|
#define TRACK_DESIGNATION_OFFSET 0x99
|
|
|
|
|
|
|
|
#define NUM_DESIGNATIONS 8
|
|
|
|
|
|
|
|
// MIDI device types for designation
|
|
|
|
#define HMI_DEV_GM 0xA000 // Generic General MIDI (not a real device)
|
|
|
|
#define HMI_DEV_MPU401 0xA001 // MPU-401, Roland Sound Canvas, Ensoniq SoundScape, Rolad RAP-10
|
|
|
|
#define HMI_DEV_OPL2 0xA002 // SoundBlaster (Pro), ESS AudioDrive
|
|
|
|
#define HMI_DEV_MT32 0xA004 // MT-32
|
|
|
|
#define HMI_DEV_SBAWE32 0xA008 // SoundBlaster AWE32
|
|
|
|
#define HMI_DEV_OPL3 0xA009 // SoundBlaster 16, Microsoft Sound System, Pro Audio Spectrum 16
|
|
|
|
#define HMI_DEV_GUS 0xA00A // Gravis UltraSound, Gravis UltraSound Max/Ace
|
|
|
|
|
|
|
|
|
|
|
|
// Data accessors, since this data is highly likely to be unaligned.
|
|
|
|
#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__)
|
|
|
|
inline int GetShort(const BYTE *foo)
|
|
|
|
{
|
|
|
|
return *(const short *)foo;
|
|
|
|
}
|
|
|
|
inline int GetInt(const BYTE *foo)
|
|
|
|
{
|
|
|
|
return *(const int *)foo;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
inline int GetShort(const BYTE *foo)
|
|
|
|
{
|
|
|
|
return short(foo[0] | (foo[1] << 8));
|
|
|
|
}
|
|
|
|
inline int GetInt(const BYTE *foo)
|
|
|
|
{
|
|
|
|
return int(foo[0] | (foo[1] << 8) | (foo[2] << 16) | (foo[3] << 24));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-03-05 03:10:31 +00:00
|
|
|
// TYPES -------------------------------------------------------------------
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
struct HMISong::TrackInfo
|
2006-06-20 20:30:39 +00:00
|
|
|
{
|
|
|
|
const BYTE *TrackBegin;
|
|
|
|
size_t TrackP;
|
|
|
|
size_t MaxTrackP;
|
|
|
|
DWORD Delay;
|
2008-04-26 17:03:53 +00:00
|
|
|
DWORD PlayedTime;
|
2010-09-02 23:17:58 +00:00
|
|
|
WORD Designation[NUM_DESIGNATIONS];
|
|
|
|
bool Enabled;
|
2006-06-20 20:30:39 +00:00
|
|
|
bool Finished;
|
|
|
|
BYTE RunningStatus;
|
|
|
|
|
|
|
|
DWORD ReadVarLen ();
|
|
|
|
};
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-03-05 03:10:31 +00:00
|
|
|
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
|
|
|
|
|
|
|
|
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
|
|
|
|
|
|
|
|
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
|
|
|
|
|
|
|
|
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
|
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
extern char MIDI_EventLengths[7];
|
|
|
|
extern char MIDI_CommonLengths[15];
|
2008-03-05 03:10:31 +00:00
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
// PRIVATE DATA DEFINITIONS ------------------------------------------------
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-03-05 03:10:31 +00:00
|
|
|
// PUBLIC DATA DEFINITIONS -------------------------------------------------
|
|
|
|
|
|
|
|
// CODE --------------------------------------------------------------------
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// HMISong Constructor
|
2008-03-05 03:10:31 +00:00
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// Buffers the file and does some validation of the HMI header.
|
2008-03-05 03:10:31 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
HMISong::HMISong (FILE *file, BYTE *musiccache, int len, EMIDIDevice type)
|
2008-04-11 04:59:23 +00:00
|
|
|
: MIDIStreamer(type), MusHeader(0), Tracks(0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
int p;
|
|
|
|
int i;
|
|
|
|
|
2008-03-30 00:04:09 +00:00
|
|
|
#ifdef _WIN32
|
2008-03-05 03:10:31 +00:00
|
|
|
if (ExitEvent == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2008-03-30 00:04:09 +00:00
|
|
|
#endif
|
2010-09-02 23:17:58 +00:00
|
|
|
if (len < 0x100)
|
|
|
|
{ // Way too small to be HMI.
|
|
|
|
return;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
MusHeader = new BYTE[len];
|
2008-04-03 02:31:39 +00:00
|
|
|
SongLen = len;
|
2006-04-14 12:58:52 +00:00
|
|
|
if (file != NULL)
|
|
|
|
{
|
2008-03-05 03:10:31 +00:00
|
|
|
if (fread(MusHeader, 1, len, file) != (size_t)len)
|
2006-04-14 12:58:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy(MusHeader, musiccache, len);
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2006-06-20 20:30:39 +00:00
|
|
|
// Do some validation of the MIDI file
|
2010-09-23 22:37:25 +00:00
|
|
|
if (memcmp(MusHeader, SONG_MAGIC, sizeof(SONG_MAGIC)) != 0)
|
2006-06-20 20:30:39 +00:00
|
|
|
return;
|
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
NumTracks = GetShort(MusHeader + TRACK_COUNT_OFFSET);
|
|
|
|
if (NumTracks <= 0)
|
2006-06-20 20:30:39 +00:00
|
|
|
{
|
2010-09-02 23:17:58 +00:00
|
|
|
return;
|
2006-06-20 20:30:39 +00:00
|
|
|
}
|
|
|
|
|
2008-03-05 03:10:31 +00:00
|
|
|
// The division is the number of pulses per quarter note (PPQN).
|
2010-09-23 22:37:25 +00:00
|
|
|
Division = GetShort(MusHeader + DIVISION_OFFSET);
|
|
|
|
InitialTempo = 4000000;
|
2006-06-20 20:30:39 +00:00
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
Tracks = new TrackInfo[NumTracks + 1];
|
|
|
|
int track_dir = GetInt(MusHeader + TRACK_DIR_PTR_OFFSET);
|
2006-06-20 20:30:39 +00:00
|
|
|
|
|
|
|
// Gather information about each track
|
2010-09-02 23:17:58 +00:00
|
|
|
for (i = 0, p = 0; i < NumTracks; ++i)
|
2006-06-20 20:30:39 +00:00
|
|
|
{
|
2010-09-02 23:17:58 +00:00
|
|
|
int start = GetInt(MusHeader + track_dir + i*4);
|
|
|
|
int tracklen, datastart;
|
|
|
|
|
|
|
|
if (start > len - TRACK_DESIGNATION_OFFSET - 4)
|
|
|
|
{ // Track is incomplete.
|
|
|
|
continue;
|
2006-06-20 20:30:39 +00:00
|
|
|
}
|
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
// BTW, HMI does not actually check the track header.
|
|
|
|
if (memcmp(MusHeader + start, TRACK_MAGIC, 13) != 0)
|
2006-06-20 20:30:39 +00:00
|
|
|
{
|
2010-09-02 23:17:58 +00:00
|
|
|
continue;
|
2006-06-20 20:30:39 +00:00
|
|
|
}
|
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
// The track ends where the next one begins. If this is the
|
|
|
|
// last track, then it ends at the end of the file.
|
|
|
|
if (i == NumTracks - 1)
|
|
|
|
{
|
|
|
|
tracklen = len - start;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tracklen = GetInt(MusHeader + track_dir + i*4 + 4) - start;
|
|
|
|
}
|
|
|
|
// Clamp incomplete tracks to the end of the file.
|
|
|
|
tracklen = MIN(tracklen, len - start);
|
|
|
|
if (tracklen <= 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Offset to actual MIDI events.
|
|
|
|
datastart = GetInt(MusHeader + start + TRACK_DATA_PTR_OFFSET);
|
|
|
|
tracklen -= datastart;
|
|
|
|
if (tracklen <= 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store track information
|
|
|
|
Tracks[p].TrackBegin = MusHeader + start + datastart;
|
|
|
|
Tracks[p].TrackP = 0;
|
|
|
|
Tracks[p].MaxTrackP = tracklen;
|
|
|
|
|
|
|
|
// Retrieve track designations. We can't check them yet, since we have not yet
|
|
|
|
// connected to the MIDI device.
|
|
|
|
for (int ii = 0; ii < NUM_DESIGNATIONS; ++ii)
|
|
|
|
{
|
|
|
|
Tracks[p].Designation[ii] = GetShort(MusHeader + start + TRACK_DESIGNATION_OFFSET + ii*2);
|
|
|
|
}
|
|
|
|
|
|
|
|
p++;
|
2006-06-20 20:30:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// In case there were fewer actual chunks in the file than the
|
2010-09-02 23:17:58 +00:00
|
|
|
// header specified, update NumTracks with the current value of p.
|
|
|
|
NumTracks = p;
|
2006-06-20 20:30:39 +00:00
|
|
|
|
|
|
|
if (NumTracks == 0)
|
|
|
|
{ // No tracks, so nothing to play
|
|
|
|
return;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2008-03-05 03:10:31 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// HMISong Destructor
|
2008-03-05 03:10:31 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
HMISong::~HMISong ()
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
if (Tracks != NULL)
|
|
|
|
{
|
|
|
|
delete[] Tracks;
|
|
|
|
}
|
2006-06-20 20:30:39 +00:00
|
|
|
if (MusHeader != NULL)
|
|
|
|
{
|
|
|
|
delete[] MusHeader;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2008-03-05 03:10:31 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// HMISong :: CheckCaps
|
2008-03-05 03:10:31 +00:00
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// Check track designations and disable tracks that have not been
|
|
|
|
// designated for the device we will be playing on.
|
2008-03-05 03:10:31 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2010-09-03 05:08:05 +00:00
|
|
|
void HMISong::CheckCaps(int tech)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2010-09-02 23:17:58 +00:00
|
|
|
// What's the equivalent HMI device for our technology?
|
2008-03-07 00:43:05 +00:00
|
|
|
if (tech == MOD_FMSYNTH)
|
2006-06-20 20:30:39 +00:00
|
|
|
{
|
2010-09-02 23:17:58 +00:00
|
|
|
tech = HMI_DEV_OPL3;
|
2008-03-07 00:43:05 +00:00
|
|
|
}
|
|
|
|
else if (tech == MOD_MIDIPORT)
|
|
|
|
{
|
2010-09-02 23:17:58 +00:00
|
|
|
tech = HMI_DEV_MPU401;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Good enough? Or should we just say we're GM.
|
|
|
|
tech = HMI_DEV_SBAWE32;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < NumTracks; ++i)
|
|
|
|
{
|
|
|
|
Tracks[i].Enabled = false;
|
|
|
|
// Track designations are stored in a 0-terminated array.
|
|
|
|
for (int j = 0; j < NUM_DESIGNATIONS && Tracks[i].Designation[j] != 0; ++j)
|
|
|
|
{
|
|
|
|
if (Tracks[i].Designation[j] == tech)
|
|
|
|
{
|
|
|
|
Tracks[i].Enabled = true;
|
|
|
|
}
|
|
|
|
// If a track is designated for device 0xA000, it will be played by a MIDI
|
|
|
|
// driver for device types 0xA000, 0xA001, and 0xA008. Why this does not
|
|
|
|
// include the GUS, I do not know.
|
|
|
|
else if (Tracks[i].Designation[j] == HMI_DEV_GM)
|
|
|
|
{
|
|
|
|
Tracks[i].Enabled = (tech == HMI_DEV_MPU401 || tech == HMI_DEV_SBAWE32);
|
|
|
|
}
|
|
|
|
// If a track is designated for device 0xA002, it will be played by a MIDI
|
|
|
|
// driver for device types 0xA002 or 0xA009.
|
|
|
|
else if (Tracks[i].Designation[j] == HMI_DEV_OPL2)
|
|
|
|
{
|
|
|
|
Tracks[i].Enabled = (tech == HMI_DEV_OPL3);
|
|
|
|
}
|
|
|
|
// Any other designation must match the specific MIDI driver device number.
|
|
|
|
// (Which we handled first above.)
|
|
|
|
|
|
|
|
if (Tracks[i].Enabled)
|
|
|
|
{ // This track's been enabled, so we can stop checking other designations.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-06-20 20:30:39 +00:00
|
|
|
}
|
2008-03-05 03:10:31 +00:00
|
|
|
}
|
2006-06-20 20:30:39 +00:00
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-03-05 03:10:31 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// HMISong :: DoInitialSetup
|
2008-03-05 03:10:31 +00:00
|
|
|
//
|
|
|
|
// Sets the starting channel volumes.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
void HMISong :: DoInitialSetup()
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-03-05 03:10:31 +00:00
|
|
|
for (int i = 0; i < 16; ++i)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-03-05 03:10:31 +00:00
|
|
|
ChannelVolumes[i] = 100;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-05 03:10:31 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// HMISong :: DoRestart
|
2008-03-05 03:10:31 +00:00
|
|
|
//
|
|
|
|
// Rewinds every track.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
void HMISong :: DoRestart()
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-03-05 03:10:31 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
// Set initial state.
|
2010-09-02 23:17:58 +00:00
|
|
|
FakeTrack = &Tracks[NumTracks];
|
|
|
|
NoteOffs.Clear();
|
|
|
|
for (i = 0; i <= NumTracks; ++i)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-03-05 03:10:31 +00:00
|
|
|
Tracks[i].TrackP = 0;
|
|
|
|
Tracks[i].Finished = false;
|
|
|
|
Tracks[i].RunningStatus = 0;
|
2008-04-26 17:03:53 +00:00
|
|
|
Tracks[i].PlayedTime = 0;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2008-03-05 03:10:31 +00:00
|
|
|
ProcessInitialMetaEvents ();
|
|
|
|
for (i = 0; i < NumTracks; ++i)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-03-05 03:10:31 +00:00
|
|
|
Tracks[i].Delay = Tracks[i].ReadVarLen();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2010-09-02 23:17:58 +00:00
|
|
|
Tracks[i].Delay = 0; // for the FakeTrack
|
|
|
|
Tracks[i].Enabled = true;
|
2008-03-05 03:10:31 +00:00
|
|
|
TrackDue = Tracks;
|
|
|
|
TrackDue = FindNextDue();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2008-03-05 03:10:31 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// HMISong :: CheckDone
|
2008-03-05 03:10:31 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
bool HMISong::CheckDone()
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-03-05 03:10:31 +00:00
|
|
|
return TrackDue == NULL;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2008-03-05 03:10:31 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// HMISong :: MakeEvents
|
2008-03-05 03:10:31 +00:00
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// Copies MIDI events from the file and puts them into a MIDI stream
|
2008-03-05 03:10:31 +00:00
|
|
|
// buffer. Returns the new position in the buffer.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
DWORD *HMISong::MakeEvents(DWORD *events, DWORD *max_event_p, DWORD max_time)
|
2008-03-05 03:10:31 +00:00
|
|
|
{
|
2008-03-30 02:51:34 +00:00
|
|
|
DWORD *start_events;
|
2008-03-05 03:10:31 +00:00
|
|
|
DWORD tot_time = 0;
|
|
|
|
DWORD time = 0;
|
2008-03-30 02:51:34 +00:00
|
|
|
DWORD delay;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-03-30 02:51:34 +00:00
|
|
|
start_events = events;
|
2008-03-05 03:10:31 +00:00
|
|
|
while (TrackDue && events < max_event_p && tot_time <= max_time)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-04-26 17:03:53 +00:00
|
|
|
// It's possible that this tick may be nothing but meta-events and
|
2008-03-30 02:51:34 +00:00
|
|
|
// not generate any real events. Repeat this until we actually
|
|
|
|
// get some output so we don't send an empty buffer to the MIDI
|
|
|
|
// device.
|
|
|
|
do
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-03-30 02:51:34 +00:00
|
|
|
delay = TrackDue->Delay;
|
|
|
|
time += delay;
|
|
|
|
// Advance time for all tracks by the amount needed for the one up next.
|
|
|
|
tot_time += delay * Tempo / Division;
|
|
|
|
AdvanceTracks(delay);
|
|
|
|
// Play all events for this tick.
|
|
|
|
do
|
2006-06-20 20:30:39 +00:00
|
|
|
{
|
2008-03-30 02:51:34 +00:00
|
|
|
DWORD *new_events = SendCommand(events, TrackDue, time);
|
|
|
|
TrackDue = FindNextDue();
|
|
|
|
if (new_events != events)
|
2006-06-20 20:30:39 +00:00
|
|
|
{
|
2008-03-30 02:51:34 +00:00
|
|
|
time = 0;
|
2006-06-20 20:30:39 +00:00
|
|
|
}
|
2008-03-30 02:51:34 +00:00
|
|
|
events = new_events;
|
2006-06-20 20:30:39 +00:00
|
|
|
}
|
2008-03-30 02:51:34 +00:00
|
|
|
while (TrackDue && TrackDue->Delay == 0 && events < max_event_p);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2008-03-30 02:51:34 +00:00
|
|
|
while (start_events == events && TrackDue);
|
|
|
|
time = 0;
|
|
|
|
}
|
|
|
|
return events;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// HMISong :: AdvanceTracks
|
2008-03-30 02:51:34 +00:00
|
|
|
//
|
|
|
|
// Advaces time for all tracks by the specified amount.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
void HMISong::AdvanceTracks(DWORD time)
|
2008-03-30 02:51:34 +00:00
|
|
|
{
|
2010-09-02 23:17:58 +00:00
|
|
|
for (int i = 0; i <= NumTracks; ++i)
|
2008-03-30 02:51:34 +00:00
|
|
|
{
|
2010-09-02 23:17:58 +00:00
|
|
|
if (Tracks[i].Enabled && !Tracks[i].Finished)
|
2008-03-05 03:10:31 +00:00
|
|
|
{
|
2008-03-30 02:51:34 +00:00
|
|
|
Tracks[i].Delay -= time;
|
2008-04-26 17:03:53 +00:00
|
|
|
Tracks[i].PlayedTime += time;
|
2008-03-05 03:10:31 +00:00
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2010-09-02 23:17:58 +00:00
|
|
|
NoteOffs.AdvanceTime(time);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2008-03-05 03:10:31 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// HMISong :: SendCommand
|
2008-03-05 03:10:31 +00:00
|
|
|
//
|
|
|
|
// Places a single MIDIEVENT in the event buffer.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2006-06-20 20:30:39 +00:00
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
DWORD *HMISong::SendCommand (DWORD *events, TrackInfo *track, DWORD delay)
|
2006-06-20 20:30:39 +00:00
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
BYTE event, data1 = 0, data2 = 0;
|
2010-09-02 23:17:58 +00:00
|
|
|
|
|
|
|
// If the next event comes from the fake track, pop an entry off the note-off queue.
|
|
|
|
if (track == FakeTrack)
|
|
|
|
{
|
|
|
|
AutoNoteOff off;
|
|
|
|
NoteOffs.Pop(off);
|
|
|
|
events[0] = delay;
|
|
|
|
events[1] = 0;
|
|
|
|
events[2] = MIDI_NOTEON | off.Channel | (off.Key << 8);
|
|
|
|
return events + 3;
|
|
|
|
}
|
2006-06-20 20:30:39 +00:00
|
|
|
|
|
|
|
CHECK_FINISHED
|
|
|
|
event = track->TrackBegin[track->TrackP++];
|
|
|
|
CHECK_FINISHED
|
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
if (event != MIDI_SYSEX && event != MIDI_META && event != MIDI_SYSEXEND && event != 0xFe)
|
2006-06-20 20:30:39 +00:00
|
|
|
{
|
|
|
|
// Normal short message
|
|
|
|
if ((event & 0xF0) == 0xF0)
|
|
|
|
{
|
2010-09-02 23:17:58 +00:00
|
|
|
if (MIDI_CommonLengths[event & 15] > 0)
|
2006-06-20 20:30:39 +00:00
|
|
|
{
|
|
|
|
data1 = track->TrackBegin[track->TrackP++];
|
2010-09-02 23:17:58 +00:00
|
|
|
if (MIDI_CommonLengths[event & 15] > 1)
|
2006-06-20 20:30:39 +00:00
|
|
|
{
|
|
|
|
data2 = track->TrackBegin[track->TrackP++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((event & 0x80) == 0)
|
|
|
|
{
|
|
|
|
data1 = event;
|
|
|
|
event = track->RunningStatus;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
track->RunningStatus = event;
|
|
|
|
data1 = track->TrackBegin[track->TrackP++];
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK_FINISHED
|
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
if (MIDI_EventLengths[(event&0x70)>>4] == 2)
|
2006-06-20 20:30:39 +00:00
|
|
|
{
|
|
|
|
data2 = track->TrackBegin[track->TrackP++];
|
|
|
|
}
|
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
// Monitor channel volume controller changes.
|
|
|
|
if ((event & 0x70) == (MIDI_CTRLCHANGE & 0x70) && data1 == 7)
|
2006-06-20 20:30:39 +00:00
|
|
|
{
|
2010-09-02 23:17:58 +00:00
|
|
|
data2 = VolumeControllerChange(event & 15, data2);
|
2006-06-20 20:30:39 +00:00
|
|
|
}
|
2010-09-02 23:17:58 +00:00
|
|
|
|
2008-04-26 17:12:37 +00:00
|
|
|
events[0] = delay;
|
|
|
|
events[1] = 0;
|
2010-09-02 23:17:58 +00:00
|
|
|
if (event != MIDI_META)
|
2006-06-20 20:30:39 +00:00
|
|
|
{
|
2008-04-26 17:12:37 +00:00
|
|
|
events[2] = event | (data1<<8) | (data2<<16);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
events[2] = MEVT_NOP;
|
2006-06-20 20:30:39 +00:00
|
|
|
}
|
2008-04-26 17:12:37 +00:00
|
|
|
events += 3;
|
2010-09-02 23:17:58 +00:00
|
|
|
|
|
|
|
if ((event & 0x70) == (MIDI_NOTEON & 0x70))
|
|
|
|
{ // HMI note on events include the time until an implied note off event.
|
|
|
|
NoteOffs.AddNoteOff(track->ReadVarLen(), event & 0x0F, data1);
|
|
|
|
}
|
2006-06-20 20:30:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-03-05 03:10:31 +00:00
|
|
|
// Skip SysEx events just because I don't want to bother with them.
|
|
|
|
// The old MIDI player ignored them too, so this won't break
|
|
|
|
// anything that played before.
|
|
|
|
if (event == MIDI_SYSEX || event == MIDI_SYSEXEND)
|
2006-06-20 20:30:39 +00:00
|
|
|
{
|
|
|
|
len = track->ReadVarLen ();
|
|
|
|
track->TrackP += len;
|
|
|
|
}
|
2008-03-05 03:10:31 +00:00
|
|
|
else if (event == MIDI_META)
|
2006-06-20 20:30:39 +00:00
|
|
|
{
|
|
|
|
// It's a meta-event
|
|
|
|
event = track->TrackBegin[track->TrackP++];
|
|
|
|
CHECK_FINISHED
|
|
|
|
len = track->ReadVarLen ();
|
|
|
|
CHECK_FINISHED
|
|
|
|
|
|
|
|
if (track->TrackP + len <= track->MaxTrackP)
|
|
|
|
{
|
|
|
|
switch (event)
|
|
|
|
{
|
2008-03-05 03:10:31 +00:00
|
|
|
case MIDI_META_EOT:
|
2006-06-20 20:30:39 +00:00
|
|
|
track->Finished = true;
|
|
|
|
break;
|
|
|
|
|
2008-03-05 03:10:31 +00:00
|
|
|
case MIDI_META_TEMPO:
|
2006-06-20 20:30:39 +00:00
|
|
|
Tempo =
|
|
|
|
(track->TrackBegin[track->TrackP+0]<<16) |
|
|
|
|
(track->TrackBegin[track->TrackP+1]<<8) |
|
|
|
|
(track->TrackBegin[track->TrackP+2]);
|
2008-03-05 03:10:31 +00:00
|
|
|
events[0] = delay;
|
|
|
|
events[1] = 0;
|
|
|
|
events[2] = (MEVT_TEMPO << 24) | Tempo;
|
|
|
|
events += 3;
|
2006-06-20 20:30:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
track->TrackP += len;
|
|
|
|
if (track->TrackP == track->MaxTrackP)
|
|
|
|
{
|
|
|
|
track->Finished = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
track->Finished = true;
|
|
|
|
}
|
|
|
|
}
|
2010-09-02 23:17:58 +00:00
|
|
|
else if (event == 0xFE)
|
|
|
|
{ // Skip unknown HMI events.
|
|
|
|
event = track->TrackBegin[track->TrackP++];
|
|
|
|
CHECK_FINISHED
|
|
|
|
if (event == 0x13 || event == 0x15)
|
|
|
|
{
|
|
|
|
track->TrackP += 6;
|
|
|
|
}
|
|
|
|
else if (event == 0x12 || event == 0x14)
|
|
|
|
{
|
|
|
|
track->TrackP += 2;
|
|
|
|
}
|
|
|
|
else if (event == 0x10)
|
|
|
|
{
|
|
|
|
track->TrackP += 2;
|
|
|
|
CHECK_FINISHED
|
|
|
|
track->TrackP += track->TrackBegin[track->TrackP] + 5;
|
|
|
|
CHECK_FINISHED
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // No idea.
|
|
|
|
track->Finished = true;
|
|
|
|
}
|
|
|
|
}
|
2006-06-20 20:30:39 +00:00
|
|
|
}
|
|
|
|
if (!track->Finished)
|
|
|
|
{
|
2008-03-05 03:10:31 +00:00
|
|
|
track->Delay = track->ReadVarLen();
|
2006-06-20 20:30:39 +00:00
|
|
|
}
|
2008-03-05 03:10:31 +00:00
|
|
|
return events;
|
2006-06-20 20:30:39 +00:00
|
|
|
}
|
|
|
|
|
2008-03-05 03:10:31 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// HMISong :: ProcessInitialMetaEvents
|
2008-03-05 03:10:31 +00:00
|
|
|
//
|
|
|
|
// Handle all the meta events at the start of each track.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2006-06-20 20:30:39 +00:00
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
void HMISong::ProcessInitialMetaEvents ()
|
2006-06-20 20:30:39 +00:00
|
|
|
{
|
|
|
|
TrackInfo *track;
|
|
|
|
int i;
|
|
|
|
BYTE event;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
for (i = 0; i < NumTracks; ++i)
|
|
|
|
{
|
|
|
|
track = &Tracks[i];
|
|
|
|
while (!track->Finished &&
|
|
|
|
track->TrackP < track->MaxTrackP - 4 &&
|
|
|
|
track->TrackBegin[track->TrackP] == 0 &&
|
|
|
|
track->TrackBegin[track->TrackP+1] == 0xFF)
|
|
|
|
{
|
|
|
|
event = track->TrackBegin[track->TrackP+2];
|
|
|
|
track->TrackP += 3;
|
|
|
|
len = track->ReadVarLen ();
|
|
|
|
if (track->TrackP + len <= track->MaxTrackP)
|
|
|
|
{
|
|
|
|
switch (event)
|
|
|
|
{
|
2008-03-05 03:10:31 +00:00
|
|
|
case MIDI_META_EOT:
|
2006-06-20 20:30:39 +00:00
|
|
|
track->Finished = true;
|
|
|
|
break;
|
|
|
|
|
2008-03-05 03:10:31 +00:00
|
|
|
case MIDI_META_TEMPO:
|
|
|
|
SetTempo(
|
2006-06-20 20:30:39 +00:00
|
|
|
(track->TrackBegin[track->TrackP+0]<<16) |
|
|
|
|
(track->TrackBegin[track->TrackP+1]<<8) |
|
2008-03-05 03:10:31 +00:00
|
|
|
(track->TrackBegin[track->TrackP+2])
|
|
|
|
);
|
2006-06-20 20:30:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
track->TrackP += len;
|
|
|
|
}
|
|
|
|
if (track->TrackP >= track->MaxTrackP - 4)
|
|
|
|
{
|
|
|
|
track->Finished = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-05 03:10:31 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// HMISong :: TrackInfo :: ReadVarLen
|
2008-03-05 03:10:31 +00:00
|
|
|
//
|
|
|
|
// Reads a variable-length SMF number.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
DWORD HMISong::TrackInfo::ReadVarLen ()
|
2006-06-20 20:30:39 +00:00
|
|
|
{
|
|
|
|
DWORD time = 0, t = 0x80;
|
|
|
|
|
|
|
|
while ((t & 0x80) && TrackP < MaxTrackP)
|
|
|
|
{
|
|
|
|
t = TrackBegin[TrackP++];
|
|
|
|
time = (time << 7) | (t & 127);
|
|
|
|
}
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
2008-03-05 03:10:31 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// HMISong :: NoteOffQueue :: AddNoteOff
|
2008-03-05 03:10:31 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
void HMISong::NoteOffQueue::AddNoteOff(DWORD delay, BYTE channel, BYTE key)
|
2006-06-20 20:30:39 +00:00
|
|
|
{
|
2010-09-02 23:17:58 +00:00
|
|
|
unsigned int i = Reserve(1);
|
|
|
|
while (i > 0 && (*this)[Parent(i)].Delay > delay)
|
2006-06-20 20:30:39 +00:00
|
|
|
{
|
2010-09-02 23:17:58 +00:00
|
|
|
(*this)[i] = (*this)[Parent(i)];
|
|
|
|
i = Parent(i);
|
2006-06-20 20:30:39 +00:00
|
|
|
}
|
2010-09-02 23:17:58 +00:00
|
|
|
(*this)[i].Delay = delay;
|
|
|
|
(*this)[i].Channel = channel;
|
|
|
|
(*this)[i].Key = key;
|
|
|
|
}
|
2006-06-20 20:30:39 +00:00
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// HMISong :: NoteOffQueue :: Pop
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2006-06-20 20:30:39 +00:00
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
bool HMISong::NoteOffQueue::Pop(AutoNoteOff &item)
|
|
|
|
{
|
|
|
|
item = (*this)[0];
|
2010-09-04 18:21:51 +00:00
|
|
|
if (TArray<AutoNoteOff>::Pop((*this)[0]))
|
2010-09-02 23:17:58 +00:00
|
|
|
{
|
|
|
|
Heapify();
|
|
|
|
return true;
|
2006-06-20 20:30:39 +00:00
|
|
|
}
|
2010-09-02 23:17:58 +00:00
|
|
|
return false;
|
2006-06-20 20:30:39 +00:00
|
|
|
}
|
2008-03-05 03:10:31 +00:00
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// HMISong :: NoteOffQueue :: AdvanceTime
|
2008-03-05 03:10:31 +00:00
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void HMISong::NoteOffQueue::AdvanceTime(DWORD time)
|
|
|
|
{
|
|
|
|
// Because the time is decreasing by the same amount for every entry,
|
|
|
|
// the heap property is maintained.
|
|
|
|
for (unsigned int i = 0; i < Size(); ++i)
|
|
|
|
{
|
|
|
|
assert((*this)[i].Delay >= time);
|
|
|
|
(*this)[i].Delay -= time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// HMISong :: NoteOffQueue :: Heapify
|
2008-03-05 03:10:31 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
void HMISong::NoteOffQueue::Heapify()
|
2008-03-05 03:10:31 +00:00
|
|
|
{
|
2010-09-02 23:17:58 +00:00
|
|
|
unsigned int i = 0;
|
|
|
|
for (;;)
|
2008-03-05 03:10:31 +00:00
|
|
|
{
|
2010-09-02 23:17:58 +00:00
|
|
|
unsigned int l = Left(i);
|
|
|
|
unsigned int r = Right(i);
|
|
|
|
unsigned int smallest = i;
|
|
|
|
if (l < Size() && (*this)[l].Delay < (*this)[i].Delay)
|
|
|
|
{
|
|
|
|
smallest = l;
|
|
|
|
}
|
|
|
|
if (r < Size() && (*this)[r].Delay < (*this)[smallest].Delay)
|
|
|
|
{
|
|
|
|
smallest = r;
|
|
|
|
}
|
|
|
|
if (smallest == i)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
swapvalues((*this)[i], (*this)[smallest]);
|
|
|
|
i = smallest;
|
2008-03-05 03:10:31 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-03 02:31:39 +00:00
|
|
|
|
2008-04-09 03:55:04 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// HMISong :: FindNextDue
|
2008-04-09 03:55:04 +00:00
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// Scans every track for the next event to play. Returns NULL if all events
|
|
|
|
// have been consumed.
|
2008-04-09 03:55:04 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
HMISong::TrackInfo *HMISong::FindNextDue ()
|
2008-04-09 03:55:04 +00:00
|
|
|
{
|
2010-09-02 23:17:58 +00:00
|
|
|
TrackInfo *track;
|
|
|
|
DWORD best;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (TrackDue != FakeTrack && !TrackDue->Finished && TrackDue->Delay == 0)
|
2008-04-09 03:55:04 +00:00
|
|
|
{
|
2010-09-02 23:17:58 +00:00
|
|
|
return TrackDue;
|
|
|
|
}
|
2008-04-09 03:55:04 +00:00
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
// Check regular tracks.
|
|
|
|
track = NULL;
|
|
|
|
best = 0xFFFFFFFF;
|
|
|
|
for (i = 0; i < NumTracks; ++i)
|
|
|
|
{
|
|
|
|
if (Tracks[i].Enabled && !Tracks[i].Finished && Tracks[i].Delay < best)
|
2008-04-09 03:55:04 +00:00
|
|
|
{
|
2010-09-02 23:17:58 +00:00
|
|
|
best = Tracks[i].Delay;
|
|
|
|
track = &Tracks[i];
|
2008-04-09 03:55:04 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-02 23:17:58 +00:00
|
|
|
// Check automatic note-offs.
|
|
|
|
if (NoteOffs.Size() != 0 && NoteOffs[0].Delay <= best)
|
|
|
|
{
|
|
|
|
FakeTrack->Delay = NoteOffs[0].Delay;
|
|
|
|
return FakeTrack;
|
|
|
|
}
|
|
|
|
return track;
|
|
|
|
}
|
|
|
|
|
2008-04-09 03:55:04 +00:00
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// HMISong :: SetTempo
|
|
|
|
//
|
|
|
|
// Sets the tempo from a track's initial meta events.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2008-04-12 05:04:37 +00:00
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
void HMISong::SetTempo(int new_tempo)
|
|
|
|
{
|
|
|
|
if (0 == MIDI->SetTempo(new_tempo))
|
2008-04-09 03:55:04 +00:00
|
|
|
{
|
2010-09-02 23:17:58 +00:00
|
|
|
Tempo = new_tempo;
|
2008-04-09 03:55:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-03 02:31:39 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// HMISong :: GetOPLDumper
|
2008-04-03 02:31:39 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
MusInfo *HMISong::GetOPLDumper(const char *filename)
|
2008-04-03 02:31:39 +00:00
|
|
|
{
|
2010-09-02 23:17:58 +00:00
|
|
|
return new HMISong(this, filename, MIDI_OPL);
|
2008-04-03 02:31:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// HMISong :: GetWaveDumper
|
2008-04-03 02:31:39 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
MusInfo *HMISong::GetWaveDumper(const char *filename, int rate)
|
2008-04-19 21:36:53 +00:00
|
|
|
{
|
2010-09-03 05:08:05 +00:00
|
|
|
return new HMISong(this, filename, MIDI_GUS);
|
2008-04-19 21:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
2010-09-02 23:17:58 +00:00
|
|
|
// HMISong File Dumping Constructor
|
2008-04-19 21:36:53 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2010-09-02 23:17:58 +00:00
|
|
|
HMISong::HMISong(const HMISong *original, const char *filename, EMIDIDevice type)
|
2008-04-19 21:36:53 +00:00
|
|
|
: MIDIStreamer(filename, type)
|
2008-04-03 02:31:39 +00:00
|
|
|
{
|
|
|
|
SongLen = original->SongLen;
|
|
|
|
MusHeader = new BYTE[original->SongLen];
|
|
|
|
memcpy(MusHeader, original->MusHeader, original->SongLen);
|
|
|
|
NumTracks = original->NumTracks;
|
|
|
|
Division = original->Division;
|
|
|
|
Tempo = InitialTempo = original->InitialTempo;
|
|
|
|
Tracks = new TrackInfo[NumTracks];
|
|
|
|
for (int i = 0; i < NumTracks; ++i)
|
|
|
|
{
|
|
|
|
TrackInfo *newtrack = &Tracks[i];
|
|
|
|
const TrackInfo *oldtrack = &original->Tracks[i];
|
|
|
|
|
|
|
|
newtrack->TrackBegin = MusHeader + (oldtrack->TrackBegin - original->MusHeader);
|
|
|
|
newtrack->TrackP = 0;
|
|
|
|
newtrack->MaxTrackP = oldtrack->MaxTrackP;
|
|
|
|
}
|
|
|
|
}
|