JANITORIAL: Remove underscores from MidiParser variable names.

This commit is contained in:
Alyssa Milburn 2012-09-07 22:57:14 +02:00
parent 5684475169
commit f08978a075
9 changed files with 350 additions and 350 deletions

View file

@ -32,24 +32,24 @@
////////////////////////////////////////////////// //////////////////////////////////////////////////
MidiParser::MidiParser() : MidiParser::MidiParser() :
_hanging_notes_count(0), _hangingNotesCount(0),
_driver(0), _driver(0),
_timer_rate(0x4A0000), _timerRate(0x4A0000),
_ppqn(96), _ppqn(96),
_tempo(500000), _tempo(500000),
_psec_per_tick(5208), // 500000 / 96 _psecPerTick(5208), // 500000 / 96
_autoLoop(false), _autoLoop(false),
_smartJump(false), _smartJump(false),
_centerPitchWheelOnUnload(false), _centerPitchWheelOnUnload(false),
_sendSustainOffOnNotesOff(false), _sendSustainOffOnNotesOff(false),
_num_tracks(0), _numTracks(0),
_active_track(255), _activeTrack(255),
_abort_parse(0) { _abortParse(0) {
memset(_active_notes, 0, sizeof(_active_notes)); memset(_activeNotes, 0, sizeof(_activeNotes));
_next_event.start = NULL; _nextEvent.start = NULL;
_next_event.delta = 0; _nextEvent.delta = 0;
_next_event.event = 0; _nextEvent.event = 0;
_next_event.length = 0; _nextEvent.length = 0;
} }
void MidiParser::property(int prop, int value) { void MidiParser::property(int prop, int value) {
@ -76,7 +76,7 @@ void MidiParser::sendToDriver(uint32 b) {
void MidiParser::setTempo(uint32 tempo) { void MidiParser::setTempo(uint32 tempo) {
_tempo = tempo; _tempo = tempo;
if (_ppqn) if (_ppqn)
_psec_per_tick = (tempo + (_ppqn >> 2)) / _ppqn; _psecPerTick = (tempo + (_ppqn >> 2)) / _ppqn;
} }
// This is the conventional (i.e. SMF) variable length quantity // This is the conventional (i.e. SMF) variable length quantity
@ -100,44 +100,44 @@ void MidiParser::activeNote(byte channel, byte note, bool active) {
return; return;
if (active) if (active)
_active_notes[note] |= (1 << channel); _activeNotes[note] |= (1 << channel);
else else
_active_notes[note] &= ~(1 << channel); _activeNotes[note] &= ~(1 << channel);
// See if there are hanging notes that we can cancel // See if there are hanging notes that we can cancel
NoteTimer *ptr = _hanging_notes; NoteTimer *ptr = _hangingNotes;
int i; int i;
for (i = ARRAYSIZE(_hanging_notes); i; --i, ++ptr) { for (i = ARRAYSIZE(_hangingNotes); i; --i, ++ptr) {
if (ptr->channel == channel && ptr->note == note && ptr->time_left) { if (ptr->channel == channel && ptr->note == note && ptr->timeLeft) {
ptr->time_left = 0; ptr->timeLeft = 0;
--_hanging_notes_count; --_hangingNotesCount;
break; break;
} }
} }
} }
void MidiParser::hangingNote(byte channel, byte note, uint32 time_left, bool recycle) { void MidiParser::hangingNote(byte channel, byte note, uint32 timeLeft, bool recycle) {
NoteTimer *best = 0; NoteTimer *best = 0;
NoteTimer *ptr = _hanging_notes; NoteTimer *ptr = _hangingNotes;
int i; int i;
if (_hanging_notes_count >= ARRAYSIZE(_hanging_notes)) { if (_hangingNotesCount >= ARRAYSIZE(_hangingNotes)) {
warning("MidiParser::hangingNote(): Exceeded polyphony"); warning("MidiParser::hangingNote(): Exceeded polyphony");
return; return;
} }
for (i = ARRAYSIZE(_hanging_notes); i; --i, ++ptr) { for (i = ARRAYSIZE(_hangingNotes); i; --i, ++ptr) {
if (ptr->channel == channel && ptr->note == note) { if (ptr->channel == channel && ptr->note == note) {
if (ptr->time_left && ptr->time_left < time_left && recycle) if (ptr->timeLeft && ptr->timeLeft < timeLeft && recycle)
return; return;
best = ptr; best = ptr;
if (ptr->time_left) { if (ptr->timeLeft) {
if (recycle) if (recycle)
sendToDriver(0x80 | channel, note, 0); sendToDriver(0x80 | channel, note, 0);
--_hanging_notes_count; --_hangingNotesCount;
} }
break; break;
} else if (!best && ptr->time_left == 0) { } else if (!best && ptr->timeLeft == 0) {
best = ptr; best = ptr;
} }
} }
@ -146,14 +146,14 @@ void MidiParser::hangingNote(byte channel, byte note, uint32 time_left, bool rec
// length, if the note should be turned on and off in // length, if the note should be turned on and off in
// the same iteration. For now just set it to 1 and // the same iteration. For now just set it to 1 and
// we'll turn it off in the next cycle. // we'll turn it off in the next cycle.
if (!time_left || time_left & 0x80000000) if (!timeLeft || timeLeft & 0x80000000)
time_left = 1; timeLeft = 1;
if (best) { if (best) {
best->channel = channel; best->channel = channel;
best->note = note; best->note = note;
best->time_left = time_left; best->timeLeft = timeLeft;
++_hanging_notes_count; ++_hangingNotesCount;
} else { } else {
// We checked this up top. We should never get here! // We checked this up top. We should never get here!
warning("MidiParser::hangingNote(): Internal error"); warning("MidiParser::hangingNote(): Internal error");
@ -161,45 +161,45 @@ void MidiParser::hangingNote(byte channel, byte note, uint32 time_left, bool rec
} }
void MidiParser::onTimer() { void MidiParser::onTimer() {
uint32 end_time; uint32 endTime;
uint32 event_time; uint32 eventTime;
if (!_position._play_pos || !_driver) if (!_position._playPos || !_driver)
return; return;
_abort_parse = false; _abortParse = false;
end_time = _position._play_time + _timer_rate; endTime = _position._playTime + _timerRate;
// Scan our hanging notes for any // Scan our hanging notes for any
// that should be turned off. // that should be turned off.
if (_hanging_notes_count) { if (_hangingNotesCount) {
NoteTimer *ptr = &_hanging_notes[0]; NoteTimer *ptr = &_hangingNotes[0];
int i; int i;
for (i = ARRAYSIZE(_hanging_notes); i; --i, ++ptr) { for (i = ARRAYSIZE(_hangingNotes); i; --i, ++ptr) {
if (ptr->time_left) { if (ptr->timeLeft) {
if (ptr->time_left <= _timer_rate) { if (ptr->timeLeft <= _timerRate) {
sendToDriver(0x80 | ptr->channel, ptr->note, 0); sendToDriver(0x80 | ptr->channel, ptr->note, 0);
ptr->time_left = 0; ptr->timeLeft = 0;
--_hanging_notes_count; --_hangingNotesCount;
} else { } else {
ptr->time_left -= _timer_rate; ptr->timeLeft -= _timerRate;
} }
} }
} }
} }
while (!_abort_parse) { while (!_abortParse) {
EventInfo &info = _next_event; EventInfo &info = _nextEvent;
event_time = _position._last_event_time + info.delta * _psec_per_tick; eventTime = _position._lastEventTime + info.delta * _psecPerTick;
if (event_time > end_time) if (eventTime > endTime)
break; break;
// Process the next info. // Process the next info.
_position._last_event_tick += info.delta; _position._lastEventTick += info.delta;
if (info.event < 0x80) { if (info.event < 0x80) {
warning("Bad command or running status %02X", info.event); warning("Bad command or running status %02X", info.event);
_position._play_pos = 0; _position._playPos = 0;
return; return;
} }
@ -217,7 +217,7 @@ void MidiParser::onTimer() {
// as well as sending it to the output device. // as well as sending it to the output device.
if (_autoLoop) { if (_autoLoop) {
jumpToTick(0); jumpToTick(0);
parseNextEvent(_next_event); parseNextEvent(_nextEvent);
} else { } else {
stopPlaying(); stopPlaying();
_driver->metaEvent(info.ext.type, info.ext.data, (uint16)info.length); _driver->metaEvent(info.ext.type, info.ext.data, (uint16)info.length);
@ -234,7 +234,7 @@ void MidiParser::onTimer() {
activeNote(info.channel(), info.basic.param1, false); activeNote(info.channel(), info.basic.param1, false);
} else if (info.command() == 0x9) { } else if (info.command() == 0x9) {
if (info.length > 0) if (info.length > 0)
hangingNote(info.channel(), info.basic.param1, info.length * _psec_per_tick - (end_time - event_time)); hangingNote(info.channel(), info.basic.param1, info.length * _psecPerTick - (endTime - eventTime));
else else
activeNote(info.channel(), info.basic.param1, true); activeNote(info.channel(), info.basic.param1, true);
} }
@ -242,15 +242,15 @@ void MidiParser::onTimer() {
} }
if (!_abort_parse) { if (!_abortParse) {
_position._last_event_time = event_time; _position._lastEventTime = eventTime;
parseNextEvent(_next_event); parseNextEvent(_nextEvent);
} }
} }
if (!_abort_parse) { if (!_abortParse) {
_position._play_time = end_time; _position._playTime = endTime;
_position._play_tick = (_position._play_time - _position._last_event_time) / _psec_per_tick + _position._last_event_tick; _position._playTick = (_position._playTime - _position._lastEventTime) / _psecPerTick + _position._lastEventTick;
} }
} }
@ -263,20 +263,20 @@ void MidiParser::allNotesOff() {
// Turn off all active notes // Turn off all active notes
for (i = 0; i < 128; ++i) { for (i = 0; i < 128; ++i) {
for (j = 0; j < 16; ++j) { for (j = 0; j < 16; ++j) {
if (_active_notes[i] & (1 << j)) { if (_activeNotes[i] & (1 << j)) {
sendToDriver(0x80 | j, i, 0); sendToDriver(0x80 | j, i, 0);
} }
} }
} }
// Turn off all hanging notes // Turn off all hanging notes
for (i = 0; i < ARRAYSIZE(_hanging_notes); i++) { for (i = 0; i < ARRAYSIZE(_hangingNotes); i++) {
if (_hanging_notes[i].time_left) { if (_hangingNotes[i].timeLeft) {
sendToDriver(0x80 | _hanging_notes[i].channel, _hanging_notes[i].note, 0); sendToDriver(0x80 | _hangingNotes[i].channel, _hangingNotes[i].note, 0);
_hanging_notes[i].time_left = 0; _hangingNotes[i].timeLeft = 0;
} }
} }
_hanging_notes_count = 0; _hangingNotesCount = 0;
// To be sure, send an "All Note Off" event (but not all MIDI devices // To be sure, send an "All Note Off" event (but not all MIDI devices
// support this...). // support this...).
@ -287,7 +287,7 @@ void MidiParser::allNotesOff() {
sendToDriver(0xB0 | i, 0x40, 0); // Also send a sustain off event (bug #3116608) sendToDriver(0xB0 | i, 0x40, 0); // Also send a sustain off event (bug #3116608)
} }
memset(_active_notes, 0, sizeof(_active_notes)); memset(_activeNotes, 0, sizeof(_activeNotes));
} }
void MidiParser::resetTracking() { void MidiParser::resetTracking() {
@ -295,7 +295,7 @@ void MidiParser::resetTracking() {
} }
bool MidiParser::setTrack(int track) { bool MidiParser::setTrack(int track) {
if (track < 0 || track >= _num_tracks) if (track < 0 || track >= _numTracks)
return false; return false;
// We allow restarting the track via setTrack when // We allow restarting the track via setTrack when
// it isn't playing anymore. This allows us to reuse // it isn't playing anymore. This allows us to reuse
@ -308,7 +308,7 @@ bool MidiParser::setTrack(int track) {
// TODO: Check if any engine has problem with this // TODO: Check if any engine has problem with this
// handling, if so we need to find a better way to handle // handling, if so we need to find a better way to handle
// track restarts. (KYRA relies on this working) // track restarts. (KYRA relies on this working)
else if (track == _active_track && isPlaying()) else if (track == _activeTrack && isPlaying())
return true; return true;
if (_smartJump) if (_smartJump)
@ -317,10 +317,10 @@ bool MidiParser::setTrack(int track) {
allNotesOff(); allNotesOff();
resetTracking(); resetTracking();
memset(_active_notes, 0, sizeof(_active_notes)); memset(_activeNotes, 0, sizeof(_activeNotes));
_active_track = track; _activeTrack = track;
_position._play_pos = _tracks[track]; _position._playPos = _tracks[track];
parseNextEvent(_next_event); parseNextEvent(_nextEvent);
return true; return true;
} }
@ -332,29 +332,29 @@ void MidiParser::stopPlaying() {
void MidiParser::hangAllActiveNotes() { void MidiParser::hangAllActiveNotes() {
// Search for note off events until we have // Search for note off events until we have
// accounted for every active note. // accounted for every active note.
uint16 temp_active[128]; uint16 tempActive[128];
memcpy(temp_active, _active_notes, sizeof (temp_active)); memcpy(tempActive, _activeNotes, sizeof (tempActive));
uint32 advance_tick = _position._last_event_tick; uint32 advanceTick = _position._lastEventTick;
while (true) { while (true) {
int i; int i;
for (i = 0; i < 128; ++i) for (i = 0; i < 128; ++i)
if (temp_active[i] != 0) if (tempActive[i] != 0)
break; break;
if (i == 128) if (i == 128)
break; break;
parseNextEvent(_next_event); parseNextEvent(_nextEvent);
advance_tick += _next_event.delta; advanceTick += _nextEvent.delta;
if (_next_event.command() == 0x8) { if (_nextEvent.command() == 0x8) {
if (temp_active[_next_event.basic.param1] & (1 << _next_event.channel())) { if (tempActive[_nextEvent.basic.param1] & (1 << _nextEvent.channel())) {
hangingNote(_next_event.channel(), _next_event.basic.param1, (advance_tick - _position._last_event_tick) * _psec_per_tick, false); hangingNote(_nextEvent.channel(), _nextEvent.basic.param1, (advanceTick - _position._lastEventTick) * _psecPerTick, false);
temp_active[_next_event.basic.param1] &= ~(1 << _next_event.channel()); tempActive[_nextEvent.basic.param1] &= ~(1 << _nextEvent.channel());
} }
} else if (_next_event.event == 0xFF && _next_event.ext.type == 0x2F) { } else if (_nextEvent.event == 0xFF && _nextEvent.ext.type == 0x2F) {
// warning("MidiParser::hangAllActiveNotes(): Hit End of Track with active notes left"); // warning("MidiParser::hangAllActiveNotes(): Hit End of Track with active notes left");
for (i = 0; i < 128; ++i) { for (i = 0; i < 128; ++i) {
for (int j = 0; j < 16; ++j) { for (int j = 0; j < 16; ++j) {
if (temp_active[i] & (1 << j)) { if (tempActive[i] & (1 << j)) {
activeNote(j, i, false); activeNote(j, i, false);
sendToDriver(0x80 | j, i, 0); sendToDriver(0x80 | j, i, 0);
} }
@ -366,33 +366,33 @@ void MidiParser::hangAllActiveNotes() {
} }
bool MidiParser::jumpToTick(uint32 tick, bool fireEvents, bool stopNotes, bool dontSendNoteOn) { bool MidiParser::jumpToTick(uint32 tick, bool fireEvents, bool stopNotes, bool dontSendNoteOn) {
if (_active_track >= _num_tracks) if (_activeTrack >= _numTracks)
return false; return false;
Tracker currentPos(_position); Tracker currentPos(_position);
EventInfo currentEvent(_next_event); EventInfo currentEvent(_nextEvent);
resetTracking(); resetTracking();
_position._play_pos = _tracks[_active_track]; _position._playPos = _tracks[_activeTrack];
parseNextEvent(_next_event); parseNextEvent(_nextEvent);
if (tick > 0) { if (tick > 0) {
while (true) { while (true) {
EventInfo &info = _next_event; EventInfo &info = _nextEvent;
if (_position._last_event_tick + info.delta >= tick) { if (_position._lastEventTick + info.delta >= tick) {
_position._play_time += (tick - _position._last_event_tick) * _psec_per_tick; _position._playTime += (tick - _position._lastEventTick) * _psecPerTick;
_position._play_tick = tick; _position._playTick = tick;
break; break;
} }
_position._last_event_tick += info.delta; _position._lastEventTick += info.delta;
_position._last_event_time += info.delta * _psec_per_tick; _position._lastEventTime += info.delta * _psecPerTick;
_position._play_tick = _position._last_event_tick; _position._playTick = _position._lastEventTick;
_position._play_time = _position._last_event_time; _position._playTime = _position._lastEventTime;
if (info.event == 0xFF) { if (info.event == 0xFF) {
if (info.ext.type == 0x2F) { // End of track if (info.ext.type == 0x2F) { // End of track
_position = currentPos; _position = currentPos;
_next_event = currentEvent; _nextEvent = currentEvent;
return false; return false;
} else { } else {
if (info.ext.type == 0x51 && info.length >= 3) // Tempo if (info.ext.type == 0x51 && info.length >= 3) // Tempo
@ -419,36 +419,36 @@ bool MidiParser::jumpToTick(uint32 tick, bool fireEvents, bool stopNotes, bool d
} }
} }
parseNextEvent(_next_event); parseNextEvent(_nextEvent);
} }
} }
if (stopNotes) { if (stopNotes) {
if (!_smartJump || !currentPos._play_pos) { if (!_smartJump || !currentPos._playPos) {
allNotesOff(); allNotesOff();
} else { } else {
EventInfo targetEvent(_next_event); EventInfo targetEvent(_nextEvent);
Tracker targetPosition(_position); Tracker targetPosition(_position);
_position = currentPos; _position = currentPos;
_next_event = currentEvent; _nextEvent = currentEvent;
hangAllActiveNotes(); hangAllActiveNotes();
_next_event = targetEvent; _nextEvent = targetEvent;
_position = targetPosition; _position = targetPosition;
} }
} }
_abort_parse = true; _abortParse = true;
return true; return true;
} }
void MidiParser::unloadMusic() { void MidiParser::unloadMusic() {
resetTracking(); resetTracking();
allNotesOff(); allNotesOff();
_num_tracks = 0; _numTracks = 0;
_active_track = 255; _activeTrack = 255;
_abort_parse = true; _abortParse = true;
if (_centerPitchWheelOnUnload) { if (_centerPitchWheelOnUnload) {
// Center the pitch wheels in preparation for the next piece of // Center the pitch wheels in preparation for the next piece of

View file

@ -49,33 +49,33 @@ class MidiDriver_BASE;
* each Tracker location. * each Tracker location.
*/ */
struct Tracker { struct Tracker {
byte * _play_pos; ///< A pointer to the next event to be parsed byte * _playPos; ///< A pointer to the next event to be parsed
uint32 _play_time; ///< Current time in microseconds; may be in between event times uint32 _playTime; ///< Current time in microseconds; may be in between event times
uint32 _play_tick; ///< Current MIDI tick; may be in between event ticks uint32 _playTick; ///< Current MIDI tick; may be in between event ticks
uint32 _last_event_time; ///< The time, in microseconds, of the last event that was parsed uint32 _lastEventTime; ///< The time, in microseconds, of the last event that was parsed
uint32 _last_event_tick; ///< The tick at which the last parsed event occurs uint32 _lastEventTick; ///< The tick at which the last parsed event occurs
byte _running_status; ///< Cached MIDI command, for MIDI streams that rely on implied event codes byte _runningStatus; ///< Cached MIDI command, for MIDI streams that rely on implied event codes
Tracker() { clear(); } Tracker() { clear(); }
/// Copy constructor for each duplication of Tracker information. /// Copy constructor for each duplication of Tracker information.
Tracker(const Tracker &copy) : Tracker(const Tracker &copy) :
_play_pos(copy._play_pos), _playPos(copy._playPos),
_play_time(copy._play_time), _playTime(copy._playTime),
_play_tick(copy._play_tick), _playTick(copy._playTick),
_last_event_time(copy._last_event_time), _lastEventTime(copy._lastEventTime),
_last_event_tick(copy._last_event_tick), _lastEventTick(copy._lastEventTick),
_running_status(copy._running_status) _runningStatus(copy._runningStatus)
{ } { }
/// Clears all data; used by the constructor for initialization. /// Clears all data; used by the constructor for initialization.
void clear() { void clear() {
_play_pos = 0; _playPos = 0;
_play_time = 0; _playTime = 0;
_play_tick = 0; _playTick = 0;
_last_event_time = 0; _lastEventTime = 0;
_last_event_tick = 0; _lastEventTick = 0;
_running_status = 0; _runningStatus = 0;
} }
}; };
@ -119,8 +119,8 @@ struct EventInfo {
struct NoteTimer { struct NoteTimer {
byte channel; ///< The MIDI channel on which the note was played byte channel; ///< The MIDI channel on which the note was played
byte note; ///< The note number for the active note byte note; ///< The note number for the active note
uint32 time_left; ///< The time, in microseconds, remaining before the note should be turned off uint32 timeLeft; ///< The time, in microseconds, remaining before the note should be turned off
NoteTimer() : channel(0), note(0), time_left(0) {} NoteTimer() : channel(0), note(0), timeLeft(0) {}
}; };
@ -264,29 +264,29 @@ struct NoteTimer {
*/ */
class MidiParser { class MidiParser {
protected: protected:
uint16 _active_notes[128]; ///< Each uint16 is a bit mask for channels that have that note on. uint16 _activeNotes[128]; ///< Each uint16 is a bit mask for channels that have that note on.
NoteTimer _hanging_notes[32]; ///< Maintains expiration info for up to 32 notes. NoteTimer _hangingNotes[32]; ///< Maintains expiration info for up to 32 notes.
///< Used for "Smart Jump" and MIDI formats that do not include explicit Note Off events. ///< Used for "Smart Jump" and MIDI formats that do not include explicit Note Off events.
byte _hanging_notes_count; ///< Count of hanging notes, used to optimize expiration. byte _hangingNotesCount; ///< Count of hanging notes, used to optimize expiration.
MidiDriver_BASE *_driver; ///< The device to which all events will be transmitted. MidiDriver_BASE *_driver; ///< The device to which all events will be transmitted.
uint32 _timer_rate; ///< The time in microseconds between onTimer() calls. Obtained from the MidiDriver. uint32 _timerRate; ///< The time in microseconds between onTimer() calls. Obtained from the MidiDriver.
uint32 _ppqn; ///< Pulses Per Quarter Note. (We refer to "pulses" as "ticks".) uint32 _ppqn; ///< Pulses Per Quarter Note. (We refer to "pulses" as "ticks".)
uint32 _tempo; ///< Microseconds per quarter note. uint32 _tempo; ///< Microseconds per quarter note.
uint32 _psec_per_tick; ///< Microseconds per tick (_tempo / _ppqn). uint32 _psecPerTick; ///< Microseconds per tick (_tempo / _ppqn).
bool _autoLoop; ///< For lightweight clients that don't provide their own flow control. bool _autoLoop; ///< For lightweight clients that don't provide their own flow control.
bool _smartJump; ///< Support smart expiration of hanging notes when jumping bool _smartJump; ///< Support smart expiration of hanging notes when jumping
bool _centerPitchWheelOnUnload; ///< Center the pitch wheels when unloading a song bool _centerPitchWheelOnUnload; ///< Center the pitch wheels when unloading a song
bool _sendSustainOffOnNotesOff; ///< Send a sustain off on a notes off event, stopping hanging notes bool _sendSustainOffOnNotesOff; ///< Send a sustain off on a notes off event, stopping hanging notes
byte *_tracks[120]; ///< Multi-track MIDI formats are supported, up to 120 tracks. byte *_tracks[120]; ///< Multi-track MIDI formats are supported, up to 120 tracks.
byte _num_tracks; ///< Count of total tracks for multi-track MIDI formats. 1 for single-track formats. byte _numTracks; ///< Count of total tracks for multi-track MIDI formats. 1 for single-track formats.
byte _active_track; ///< Keeps track of the currently active track, in multi-track formats. byte _activeTrack; ///< Keeps track of the currently active track, in multi-track formats.
Tracker _position; ///< The current time/position in the active track. Tracker _position; ///< The current time/position in the active track.
EventInfo _next_event; ///< The next event to transmit. Events are preparsed EventInfo _nextEvent; ///< The next event to transmit. Events are preparsed
///< so each event is parsed only once; this permits ///< so each event is parsed only once; this permits
///< simulated events in certain formats. ///< simulated events in certain formats.
bool _abort_parse; ///< If a jump or other operation interrupts parsing, flag to abort. bool _abortParse; ///< If a jump or other operation interrupts parsing, flag to abort.
protected: protected:
static uint32 readVLQ(byte * &data); static uint32 readVLQ(byte * &data);
@ -295,7 +295,7 @@ protected:
virtual void parseNextEvent(EventInfo &info) = 0; virtual void parseNextEvent(EventInfo &info) = 0;
void activeNote(byte channel, byte note, bool active); void activeNote(byte channel, byte note, bool active);
void hangingNote(byte channel, byte note, uint32 ticks_left, bool recycle = true); void hangingNote(byte channel, byte note, uint32 ticksLeft, bool recycle = true);
void hangAllActiveNotes(); void hangAllActiveNotes();
virtual void sendToDriver(uint32 b); virtual void sendToDriver(uint32 b);
@ -377,18 +377,18 @@ public:
virtual void property(int prop, int value); virtual void property(int prop, int value);
void setMidiDriver(MidiDriver_BASE *driver) { _driver = driver; } void setMidiDriver(MidiDriver_BASE *driver) { _driver = driver; }
void setTimerRate(uint32 rate) { _timer_rate = rate; } void setTimerRate(uint32 rate) { _timerRate = rate; }
void setTempo(uint32 tempo); void setTempo(uint32 tempo);
void onTimer(); void onTimer();
bool isPlaying() const { return (_position._play_pos != 0); } bool isPlaying() const { return (_position._playPos != 0); }
void stopPlaying(); void stopPlaying();
bool setTrack(int track); bool setTrack(int track);
bool jumpToTick(uint32 tick, bool fireEvents = false, bool stopNotes = true, bool dontSendNoteOn = false); bool jumpToTick(uint32 tick, bool fireEvents = false, bool stopNotes = true, bool dontSendNoteOn = false);
uint32 getPPQN() { return _ppqn; } uint32 getPPQN() { return _ppqn; }
virtual uint32 getTick() { return _position._play_tick; } virtual uint32 getTick() { return _position._playTick; }
static void defaultXMidiCallback(byte eventData, void *refCon); static void defaultXMidiCallback(byte eventData, void *refCon);

View file

@ -45,8 +45,8 @@ public:
}; };
static const byte command_lengths[8] = { 3, 3, 3, 3, 2, 2, 3, 0 }; static const byte commandLengths[8] = { 3, 3, 3, 3, 2, 2, 3, 0 };
static const byte special_lengths[16] = { 0, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 }; static const byte specialLengths[16] = { 0, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 };
MidiParser_SMF::~MidiParser_SMF() { MidiParser_SMF::~MidiParser_SMF() {
free(_buffer); free(_buffer);
@ -62,8 +62,8 @@ void MidiParser_SMF::property(int prop, int value) {
} }
void MidiParser_SMF::parseNextEvent(EventInfo &info) { void MidiParser_SMF::parseNextEvent(EventInfo &info) {
info.start = _position._play_pos; info.start = _position._playPos;
info.delta = readVLQ(_position._play_pos); info.delta = readVLQ(_position._playPos);
// Process the next info. If mpMalformedPitchBends // Process the next info. If mpMalformedPitchBends
// was set, we must skip over any pitch bend events // was set, we must skip over any pitch bend events
@ -71,19 +71,19 @@ void MidiParser_SMF::parseNextEvent(EventInfo &info) {
// real pitch bend events, they're just two-byte // real pitch bend events, they're just two-byte
// prefixes before the real info. // prefixes before the real info.
do { do {
if ((_position._play_pos[0] & 0xF0) >= 0x80) if ((_position._playPos[0] & 0xF0) >= 0x80)
info.event = *(_position._play_pos++); info.event = *(_position._playPos++);
else else
info.event = _position._running_status; info.event = _position._runningStatus;
} while (_malformedPitchBends && (info.event & 0xF0) == 0xE0 && _position._play_pos++); } while (_malformedPitchBends && (info.event & 0xF0) == 0xE0 && _position._playPos++);
if (info.event < 0x80) if (info.event < 0x80)
return; return;
_position._running_status = info.event; _position._runningStatus = info.event;
switch (info.command()) { switch (info.command()) {
case 0x9: // Note On case 0x9: // Note On
info.basic.param1 = *(_position._play_pos++); info.basic.param1 = *(_position._playPos++);
info.basic.param2 = *(_position._play_pos++); info.basic.param2 = *(_position._playPos++);
if (info.basic.param2 == 0) if (info.basic.param2 == 0)
info.event = info.channel() | 0x80; info.event = info.channel() | 0x80;
info.length = 0; info.length = 0;
@ -91,7 +91,7 @@ void MidiParser_SMF::parseNextEvent(EventInfo &info) {
case 0xC: case 0xC:
case 0xD: case 0xD:
info.basic.param1 = *(_position._play_pos++); info.basic.param1 = *(_position._playPos++);
info.basic.param2 = 0; info.basic.param2 = 0;
break; break;
@ -99,20 +99,20 @@ void MidiParser_SMF::parseNextEvent(EventInfo &info) {
case 0xA: case 0xA:
case 0xB: case 0xB:
case 0xE: case 0xE:
info.basic.param1 = *(_position._play_pos++); info.basic.param1 = *(_position._playPos++);
info.basic.param2 = *(_position._play_pos++); info.basic.param2 = *(_position._playPos++);
info.length = 0; info.length = 0;
break; break;
case 0xF: // System Common, Meta or SysEx event case 0xF: // System Common, Meta or SysEx event
switch (info.event & 0x0F) { switch (info.event & 0x0F) {
case 0x2: // Song Position Pointer case 0x2: // Song Position Pointer
info.basic.param1 = *(_position._play_pos++); info.basic.param1 = *(_position._playPos++);
info.basic.param2 = *(_position._play_pos++); info.basic.param2 = *(_position._playPos++);
break; break;
case 0x3: // Song Select case 0x3: // Song Select
info.basic.param1 = *(_position._play_pos++); info.basic.param1 = *(_position._playPos++);
info.basic.param2 = 0; info.basic.param2 = 0;
break; break;
@ -126,16 +126,16 @@ void MidiParser_SMF::parseNextEvent(EventInfo &info) {
break; break;
case 0x0: // SysEx case 0x0: // SysEx
info.length = readVLQ(_position._play_pos); info.length = readVLQ(_position._playPos);
info.ext.data = _position._play_pos; info.ext.data = _position._playPos;
_position._play_pos += info.length; _position._playPos += info.length;
break; break;
case 0xF: // META event case 0xF: // META event
info.ext.type = *(_position._play_pos++); info.ext.type = *(_position._playPos++);
info.length = readVLQ(_position._play_pos); info.length = readVLQ(_position._playPos);
info.ext.data = _position._play_pos; info.ext.data = _position._playPos;
_position._play_pos += info.length; _position._playPos += info.length;
break; break;
default: default:
@ -146,8 +146,8 @@ void MidiParser_SMF::parseNextEvent(EventInfo &info) {
bool MidiParser_SMF::loadMusic(byte *data, uint32 size) { bool MidiParser_SMF::loadMusic(byte *data, uint32 size) {
uint32 len; uint32 len;
byte midi_type; byte midiType;
uint32 total_size; uint32 totalSize;
bool isGMF; bool isGMF;
unloadMusic(); unloadMusic();
@ -171,10 +171,10 @@ bool MidiParser_SMF::loadMusic(byte *data, uint32 size) {
// Verify that this MIDI either is a Type 2 // Verify that this MIDI either is a Type 2
// or has only 1 track. We do not support // or has only 1 track. We do not support
// multitrack Type 1 files. // multitrack Type 1 files.
_num_tracks = pos[2] << 8 | pos[3]; _numTracks = pos[2] << 8 | pos[3];
midi_type = pos[1]; midiType = pos[1];
if (midi_type > 2 /*|| (midi_type < 2 && _num_tracks > 1)*/) { if (midiType > 2 /*|| (midiType < 2 && _numTracks > 1)*/) {
warning("No support for a Type %d MIDI with %d tracks", (int)midi_type, (int)_num_tracks); warning("No support for a Type %d MIDI with %d tracks", (int)midiType, (int)_numTracks);
return false; return false;
} }
_ppqn = pos[4] << 8 | pos[5]; _ppqn = pos[4] << 8 | pos[5];
@ -183,8 +183,8 @@ bool MidiParser_SMF::loadMusic(byte *data, uint32 size) {
// Older GMD/MUS file with no header info. // Older GMD/MUS file with no header info.
// Assume 1 track, 192 PPQN, and no MTrk headers. // Assume 1 track, 192 PPQN, and no MTrk headers.
isGMF = true; isGMF = true;
midi_type = 0; midiType = 0;
_num_tracks = 1; _numTracks = 1;
_ppqn = 192; _ppqn = 192;
pos += 7; // 'GMD\x1' + 3 bytes of useless (translate: unknown) information pos += 7; // 'GMD\x1' + 3 bytes of useless (translate: unknown) information
} else { } else {
@ -193,14 +193,14 @@ bool MidiParser_SMF::loadMusic(byte *data, uint32 size) {
} }
// Now we identify and store the location for each track. // Now we identify and store the location for each track.
if (_num_tracks > ARRAYSIZE(_tracks)) { if (_numTracks > ARRAYSIZE(_tracks)) {
warning("Can only handle %d tracks but was handed %d", (int)ARRAYSIZE(_tracks), (int)_num_tracks); warning("Can only handle %d tracks but was handed %d", (int)ARRAYSIZE(_tracks), (int)_numTracks);
return false; return false;
} }
total_size = 0; totalSize = 0;
int tracks_read = 0; int tracksRead = 0;
while (tracks_read < _num_tracks) { while (tracksRead < _numTracks) {
if (memcmp(pos, "MTrk", 4) && !isGMF) { if (memcmp(pos, "MTrk", 4) && !isGMF) {
warning("Position: %p ('%c')", pos, *pos); warning("Position: %p ('%c')", pos, *pos);
warning("Hit invalid block '%c%c%c%c' while scanning for track locations", pos[0], pos[1], pos[2], pos[3]); warning("Hit invalid block '%c%c%c%c' while scanning for track locations", pos[0], pos[1], pos[2], pos[3]);
@ -208,11 +208,11 @@ bool MidiParser_SMF::loadMusic(byte *data, uint32 size) {
} }
// If needed, skip the MTrk and length bytes // If needed, skip the MTrk and length bytes
_tracks[tracks_read] = pos + (isGMF ? 0 : 8); _tracks[tracksRead] = pos + (isGMF ? 0 : 8);
if (!isGMF) { if (!isGMF) {
pos += 4; pos += 4;
len = read4high(pos); len = read4high(pos);
total_size += len; totalSize += len;
pos += len; pos += len;
} else { } else {
// An SMF End of Track meta event must be placed // An SMF End of Track meta event must be placed
@ -222,7 +222,7 @@ bool MidiParser_SMF::loadMusic(byte *data, uint32 size) {
data[size++] = 0x00; data[size++] = 0x00;
data[size++] = 0x00; data[size++] = 0x00;
} }
++tracks_read; ++tracksRead;
} }
// If this is a Type 1 MIDI, we need to now compress // If this is a Type 1 MIDI, we need to now compress
@ -230,13 +230,13 @@ bool MidiParser_SMF::loadMusic(byte *data, uint32 size) {
free(_buffer); free(_buffer);
_buffer = 0; _buffer = 0;
if (midi_type == 1) { if (midiType == 1) {
// FIXME: Doubled the buffer size to prevent crashes with the // FIXME: Doubled the buffer size to prevent crashes with the
// Inherit the Earth MIDIs. Jamieson630 said something about a // Inherit the Earth MIDIs. Jamieson630 said something about a
// better fix, but this will have to do in the meantime. // better fix, but this will have to do in the meantime.
_buffer = (byte *)malloc(size * 2); _buffer = (byte *)malloc(size * 2);
compressToType0(); compressToType0();
_num_tracks = 1; _numTracks = 1;
_tracks[0] = _buffer; _tracks[0] = _buffer;
} }
@ -253,48 +253,48 @@ void MidiParser_SMF::compressToType0() {
// We assume that _buffer has been allocated // We assume that _buffer has been allocated
// to sufficient size for this operation. // to sufficient size for this operation.
// using 0xFF since it could write track_pos[0 to _num_tracks] here // using 0xFF since it could write trackPos[0 to _numTracks] here
// this would cause some illegal writes and could lead to segfaults // this would cause some illegal writes and could lead to segfaults
// (it crashed for some midis for me, they're not used in any game // (it crashed for some midis for me, they're not used in any game
// scummvm supports though). *Maybe* handle this in another way, // scummvm supports though). *Maybe* handle this in another way,
// it's at the moment only to be sure, that nothing goes wrong. // it's at the moment only to be sure, that nothing goes wrong.
byte *track_pos[0xFF]; byte *trackPos[0xFF];
byte running_status[0xFF]; byte runningStatus[0xFF];
uint32 track_timer[0xFF]; uint32 trackTimer[0xFF];
uint32 delta; uint32 delta;
int i; int i;
for (i = 0; i < _num_tracks; ++i) { for (i = 0; i < _numTracks; ++i) {
running_status[i] = 0; runningStatus[i] = 0;
track_pos[i] = _tracks[i]; trackPos[i] = _tracks[i];
track_timer[i] = readVLQ(track_pos[i]); trackTimer[i] = readVLQ(trackPos[i]);
running_status[i] = 0; runningStatus[i] = 0;
} }
int best_i; int bestTrack;
uint32 length; uint32 length;
byte *output = _buffer; byte *output = _buffer;
byte *pos, *pos2; byte *pos, *pos2;
byte event; byte event;
uint32 copy_bytes; uint32 copyBytes;
bool write; bool write;
byte active_tracks = (byte)_num_tracks; byte activeTracks = (byte)_numTracks;
while (active_tracks) { while (activeTracks) {
write = true; write = true;
best_i = 255; bestTrack = 255;
for (i = 0; i < _num_tracks; ++i) { for (i = 0; i < _numTracks; ++i) {
if (track_pos[i] && (best_i == 255 || track_timer[i] < track_timer[best_i])) if (trackPos[i] && (bestTrack == 255 || trackTimer[i] < trackTimer[bestTrack]))
best_i = i; bestTrack = i;
} }
if (best_i == 255) { if (bestTrack == 255) {
warning("Premature end of tracks"); warning("Premature end of tracks");
break; break;
} }
// Initial VLQ delta computation // Initial VLQ delta computation
delta = 0; delta = 0;
length = track_timer[best_i]; length = trackTimer[bestTrack];
for (i = 0; length; ++i) { for (i = 0; length; ++i) {
delta = (delta << 8) | (length & 0x7F) | (i ? 0x80 : 0); delta = (delta << 8) | (length & 0x7F) | (i ? 0x80 : 0);
length >>= 7; length >>= 7;
@ -302,55 +302,55 @@ void MidiParser_SMF::compressToType0() {
// Process MIDI event. // Process MIDI event.
bool implicitEvent = false; bool implicitEvent = false;
copy_bytes = 0; copyBytes = 0;
pos = track_pos[best_i]; pos = trackPos[bestTrack];
do { do {
event = *(pos++); event = *(pos++);
if (event < 0x80) { if (event < 0x80) {
event = running_status[best_i]; event = runningStatus[bestTrack];
implicitEvent = true; implicitEvent = true;
} }
} while (_malformedPitchBends && (event & 0xF0) == 0xE0 && pos++); } while (_malformedPitchBends && (event & 0xF0) == 0xE0 && pos++);
running_status[best_i] = event; runningStatus[bestTrack] = event;
if (command_lengths[(event >> 4) - 8] > 0) { if (commandLengths[(event >> 4) - 8] > 0) {
copy_bytes = command_lengths[(event >> 4) - 8]; copyBytes = commandLengths[(event >> 4) - 8];
} else if (special_lengths[(event & 0x0F)] > 0) { } else if (specialLengths[(event & 0x0F)] > 0) {
copy_bytes = special_lengths[(event & 0x0F)]; copyBytes = specialLengths[(event & 0x0F)];
} else if (event == 0xF0) { } else if (event == 0xF0) {
// SysEx // SysEx
pos2 = pos; pos2 = pos;
length = readVLQ(pos); length = readVLQ(pos);
copy_bytes = 1 + (pos - pos2) + length; copyBytes = 1 + (pos - pos2) + length;
} else if (event == 0xFF) { } else if (event == 0xFF) {
// META // META
event = *(pos++); event = *(pos++);
if (event == 0x2F && active_tracks > 1) { if (event == 0x2F && activeTracks > 1) {
track_pos[best_i] = 0; trackPos[bestTrack] = 0;
write = false; write = false;
} else { } else {
pos2 = pos; pos2 = pos;
length = readVLQ(pos); length = readVLQ(pos);
copy_bytes = 2 + (pos - pos2) + length; copyBytes = 2 + (pos - pos2) + length;
} }
if (event == 0x2F) if (event == 0x2F)
--active_tracks; --activeTracks;
} else { } else {
warning("Bad MIDI command %02X", (int)event); warning("Bad MIDI command %02X", (int)event);
track_pos[best_i] = 0; trackPos[bestTrack] = 0;
} }
// Update all tracks' deltas // Update all tracks' deltas
if (write) { if (write) {
for (i = 0; i < _num_tracks; ++i) { for (i = 0; i < _numTracks; ++i) {
if (track_pos[i] && i != best_i) if (trackPos[i] && i != bestTrack)
track_timer[i] -= track_timer[best_i]; trackTimer[i] -= trackTimer[bestTrack];
} }
} }
if (track_pos[best_i]) { if (trackPos[bestTrack]) {
if (write) { if (write) {
track_timer[best_i] = 0; trackTimer[bestTrack] = 0;
// Write VLQ delta // Write VLQ delta
while (delta & 0x80) { while (delta & 0x80) {
@ -361,17 +361,17 @@ void MidiParser_SMF::compressToType0() {
// Write MIDI data // Write MIDI data
if (!implicitEvent) if (!implicitEvent)
++track_pos[best_i]; ++trackPos[bestTrack];
--copy_bytes; --copyBytes;
*output++ = running_status[best_i]; *output++ = runningStatus[bestTrack];
memcpy(output, track_pos[best_i], copy_bytes); memcpy(output, trackPos[bestTrack], copyBytes);
output += copy_bytes; output += copyBytes;
} }
// Fetch new VLQ delta for winning track // Fetch new VLQ delta for winning track
track_pos[best_i] += copy_bytes; trackPos[bestTrack] += copyBytes;
if (active_tracks) if (activeTracks)
track_timer[best_i] += readVLQ(track_pos[best_i]); trackTimer[bestTrack] += readVLQ(trackPos[bestTrack]);
} }
} }

View file

@ -65,16 +65,16 @@ uint32 MidiParser_XMIDI::readVLQ2(byte * &pos) {
} }
void MidiParser_XMIDI::parseNextEvent(EventInfo &info) { void MidiParser_XMIDI::parseNextEvent(EventInfo &info) {
info.start = _position._play_pos; info.start = _position._playPos;
info.delta = readVLQ2(_position._play_pos); info.delta = readVLQ2(_position._playPos);
// Process the next event. // Process the next event.
info.event = *(_position._play_pos++); info.event = *(_position._playPos++);
switch (info.event >> 4) { switch (info.event >> 4) {
case 0x9: // Note On case 0x9: // Note On
info.basic.param1 = *(_position._play_pos++); info.basic.param1 = *(_position._playPos++);
info.basic.param2 = *(_position._play_pos++); info.basic.param2 = *(_position._playPos++);
info.length = readVLQ(_position._play_pos); info.length = readVLQ(_position._playPos);
if (info.basic.param2 == 0) { if (info.basic.param2 == 0) {
info.event = info.channel() | 0x80; info.event = info.channel() | 0x80;
info.length = 0; info.length = 0;
@ -83,20 +83,20 @@ void MidiParser_XMIDI::parseNextEvent(EventInfo &info) {
case 0xC: case 0xC:
case 0xD: case 0xD:
info.basic.param1 = *(_position._play_pos++); info.basic.param1 = *(_position._playPos++);
info.basic.param2 = 0; info.basic.param2 = 0;
break; break;
case 0x8: case 0x8:
case 0xA: case 0xA:
case 0xE: case 0xE:
info.basic.param1 = *(_position._play_pos++); info.basic.param1 = *(_position._playPos++);
info.basic.param2 = *(_position._play_pos++); info.basic.param2 = *(_position._playPos++);
break; break;
case 0xB: case 0xB:
info.basic.param1 = *(_position._play_pos++); info.basic.param1 = *(_position._playPos++);
info.basic.param2 = *(_position._play_pos++); info.basic.param2 = *(_position._playPos++);
// This isn't a full XMIDI implementation, but it should // This isn't a full XMIDI implementation, but it should
// hopefully be "good enough" for most things. // hopefully be "good enough" for most things.
@ -104,7 +104,7 @@ void MidiParser_XMIDI::parseNextEvent(EventInfo &info) {
switch (info.basic.param1) { switch (info.basic.param1) {
// Simplified XMIDI looping. // Simplified XMIDI looping.
case 0x74: { // XMIDI_CONTROLLER_FOR_LOOP case 0x74: { // XMIDI_CONTROLLER_FOR_LOOP
byte *pos = _position._play_pos; byte *pos = _position._playPos;
if (_loopCount < ARRAYSIZE(_loop) - 1) if (_loopCount < ARRAYSIZE(_loop) - 1)
_loopCount++; _loopCount++;
else else
@ -126,9 +126,9 @@ void MidiParser_XMIDI::parseNextEvent(EventInfo &info) {
if (--_loop[_loopCount].repeat == 0) if (--_loop[_loopCount].repeat == 0)
_loopCount--; _loopCount--;
else else
_position._play_pos = _loop[_loopCount].pos; _position._playPos = _loop[_loopCount].pos;
} else { } else {
_position._play_pos = _loop[_loopCount].pos; _position._playPos = _loop[_loopCount].pos;
} }
} }
} }
@ -164,12 +164,12 @@ void MidiParser_XMIDI::parseNextEvent(EventInfo &info) {
case 0xF: // Meta or SysEx event case 0xF: // Meta or SysEx event
switch (info.event & 0x0F) { switch (info.event & 0x0F) {
case 0x2: // Song Position Pointer case 0x2: // Song Position Pointer
info.basic.param1 = *(_position._play_pos++); info.basic.param1 = *(_position._playPos++);
info.basic.param2 = *(_position._play_pos++); info.basic.param2 = *(_position._playPos++);
break; break;
case 0x3: // Song Select case 0x3: // Song Select
info.basic.param1 = *(_position._play_pos++); info.basic.param1 = *(_position._playPos++);
info.basic.param2 = 0; info.basic.param2 = 0;
break; break;
@ -183,16 +183,16 @@ void MidiParser_XMIDI::parseNextEvent(EventInfo &info) {
break; break;
case 0x0: // SysEx case 0x0: // SysEx
info.length = readVLQ(_position._play_pos); info.length = readVLQ(_position._playPos);
info.ext.data = _position._play_pos; info.ext.data = _position._playPos;
_position._play_pos += info.length; _position._playPos += info.length;
break; break;
case 0xF: // META event case 0xF: // META event
info.ext.type = *(_position._play_pos++); info.ext.type = *(_position._playPos++);
info.length = readVLQ(_position._play_pos); info.length = readVLQ(_position._playPos);
info.ext.data = _position._play_pos; info.ext.data = _position._playPos;
_position._play_pos += info.length; _position._playPos += info.length;
if (info.ext.type == 0x51 && info.length == 3) { if (info.ext.type == 0x51 && info.length == 3) {
// Tempo event. We want to make these constant 500,000. // Tempo event. We want to make these constant 500,000.
info.ext.data[0] = 0x07; info.ext.data[0] = 0x07;
@ -211,7 +211,7 @@ bool MidiParser_XMIDI::loadMusic(byte *data, uint32 size) {
uint32 i = 0; uint32 i = 0;
byte *start; byte *start;
uint32 len; uint32 len;
uint32 chunk_len; uint32 chunkLen;
char buf[32]; char buf[32];
_loopCount = -1; _loopCount = -1;
@ -230,7 +230,7 @@ bool MidiParser_XMIDI::loadMusic(byte *data, uint32 size) {
if (!memcmp(pos, "XMID", 4)) { if (!memcmp(pos, "XMID", 4)) {
warning("XMIDI doesn't have XDIR"); warning("XMIDI doesn't have XDIR");
pos += 4; pos += 4;
_num_tracks = 1; _numTracks = 1;
} else if (memcmp(pos, "XDIR", 4)) { } else if (memcmp(pos, "XDIR", 4)) {
// Not an XMIDI that we recognize // Not an XMIDI that we recognize
warning("Expected 'XDIR' but found '%c%c%c%c'", pos[0], pos[1], pos[2], pos[3]); warning("Expected 'XDIR' but found '%c%c%c%c'", pos[0], pos[1], pos[2], pos[3]);
@ -238,7 +238,7 @@ bool MidiParser_XMIDI::loadMusic(byte *data, uint32 size) {
} else { } else {
// Seems Valid // Seems Valid
pos += 4; pos += 4;
_num_tracks = 0; _numTracks = 0;
for (i = 4; i < len; i++) { for (i = 4; i < len; i++) {
// Read 4 bytes of type // Read 4 bytes of type
@ -246,34 +246,34 @@ bool MidiParser_XMIDI::loadMusic(byte *data, uint32 size) {
pos += 4; pos += 4;
// Read length of chunk // Read length of chunk
chunk_len = read4high(pos); chunkLen = read4high(pos);
// Add eight bytes // Add eight bytes
i += 8; i += 8;
if (memcmp(buf, "INFO", 4) == 0) { if (memcmp(buf, "INFO", 4) == 0) {
// Must be at least 2 bytes long // Must be at least 2 bytes long
if (chunk_len < 2) { if (chunkLen < 2) {
warning("Invalid chunk length %d for 'INFO' block", (int)chunk_len); warning("Invalid chunk length %d for 'INFO' block", (int)chunkLen);
return false; return false;
} }
_num_tracks = (byte)read2low(pos); _numTracks = (byte)read2low(pos);
if (chunk_len > 2) { if (chunkLen > 2) {
warning("Chunk length %d is greater than 2", (int)chunk_len); warning("Chunk length %d is greater than 2", (int)chunkLen);
//pos += chunk_len - 2; //pos += chunkLen - 2;
} }
break; break;
} }
// Must align // Must align
pos += (chunk_len + 1) & ~1; pos += (chunkLen + 1) & ~1;
i += (chunk_len + 1) & ~1; i += (chunkLen + 1) & ~1;
} }
// Didn't get to fill the header // Didn't get to fill the header
if (_num_tracks == 0) { if (_numTracks == 0) {
warning("Didn't find a valid track count"); warning("Didn't find a valid track count");
return false; return false;
} }
@ -303,13 +303,13 @@ bool MidiParser_XMIDI::loadMusic(byte *data, uint32 size) {
// Ok it's an XMIDI. // Ok it's an XMIDI.
// We're going to identify and store the location for each track. // We're going to identify and store the location for each track.
if (_num_tracks > ARRAYSIZE(_tracks)) { if (_numTracks > ARRAYSIZE(_tracks)) {
warning("Can only handle %d tracks but was handed %d", (int)ARRAYSIZE(_tracks), (int)_num_tracks); warning("Can only handle %d tracks but was handed %d", (int)ARRAYSIZE(_tracks), (int)_numTracks);
return false; return false;
} }
int tracks_read = 0; int tracksRead = 0;
while (tracks_read < _num_tracks) { while (tracksRead < _numTracks) {
if (!memcmp(pos, "FORM", 4)) { if (!memcmp(pos, "FORM", 4)) {
// Skip this plus the 4 bytes after it. // Skip this plus the 4 bytes after it.
pos += 8; pos += 8;
@ -325,11 +325,11 @@ bool MidiParser_XMIDI::loadMusic(byte *data, uint32 size) {
pos += (len + 1) & ~1; pos += (len + 1) & ~1;
} else if (!memcmp(pos, "EVNT", 4)) { } else if (!memcmp(pos, "EVNT", 4)) {
// Ahh! What we're looking for at last. // Ahh! What we're looking for at last.
_tracks[tracks_read] = pos + 8; // Skip the EVNT and length bytes _tracks[tracksRead] = pos + 8; // Skip the EVNT and length bytes
pos += 4; pos += 4;
len = read4high(pos); len = read4high(pos);
pos += (len + 1) & ~1; pos += (len + 1) & ~1;
++tracks_read; ++tracksRead;
} else { } else {
warning("Hit invalid block '%c%c%c%c' while scanning for track locations", pos[0], pos[1], pos[2], pos[3]); warning("Hit invalid block '%c%c%c%c' while scanning for track locations", pos[0], pos[1], pos[2], pos[3]);
return false; return false;

View file

@ -35,7 +35,7 @@ namespace AGOS {
class MidiParser_S1D : public MidiParser { class MidiParser_S1D : public MidiParser {
private: private:
byte *_data; byte *_data;
bool _no_delta; bool _noDelta;
struct Loop { struct Loop {
uint16 timer; uint16 timer;
@ -49,7 +49,7 @@ protected:
void resetTracking(); void resetTracking();
public: public:
MidiParser_S1D() : _data(0), _no_delta(false) {} MidiParser_S1D() : _data(0), _noDelta(false) {}
bool loadMusic(byte *data, uint32 size); bool loadMusic(byte *data, uint32 size);
}; };
@ -75,14 +75,14 @@ void MidiParser_S1D::chainEvent(EventInfo &info) {
} }
void MidiParser_S1D::parseNextEvent(EventInfo &info) { void MidiParser_S1D::parseNextEvent(EventInfo &info) {
info.start = _position._play_pos; info.start = _position._playPos;
info.length = 0; info.length = 0;
info.delta = _no_delta ? 0 : readVLQ2(_position._play_pos); info.delta = _noDelta ? 0 : readVLQ2(_position._playPos);
_no_delta = false; _noDelta = false;
info.event = *_position._play_pos++; info.event = *_position._playPos++;
if (!(info.event & 0x80)) { if (!(info.event & 0x80)) {
_no_delta = true; _noDelta = true;
info.event |= 0x80; info.event |= 0x80;
} }
@ -94,34 +94,34 @@ void MidiParser_S1D::parseNextEvent(EventInfo &info) {
} else { } else {
switch (info.command()) { switch (info.command()) {
case 0x8: // note off case 0x8: // note off
info.basic.param1 = *_position._play_pos++; info.basic.param1 = *_position._playPos++;
info.basic.param2 = 0; info.basic.param2 = 0;
break; break;
case 0x9: // note on case 0x9: // note on
info.basic.param1 = *_position._play_pos++; info.basic.param1 = *_position._playPos++;
info.basic.param2 = *_position._play_pos++; info.basic.param2 = *_position._playPos++;
break; break;
case 0xA: { // loop control case 0xA: { // loop control
// In case the stop mode(?) is set to 0x80 this will stop the // In case the stop mode(?) is set to 0x80 this will stop the
// track over here. // track over here.
const int16 loopIterations = int8(*_position._play_pos++); const int16 loopIterations = int8(*_position._playPos++);
if (!loopIterations) { if (!loopIterations) {
_loops[info.channel()].start = _position._play_pos; _loops[info.channel()].start = _position._playPos;
} else { } else {
if (!_loops[info.channel()].timer) { if (!_loops[info.channel()].timer) {
if (_loops[info.channel()].start) { if (_loops[info.channel()].start) {
_loops[info.channel()].timer = uint16(loopIterations); _loops[info.channel()].timer = uint16(loopIterations);
_loops[info.channel()].end = _position._play_pos; _loops[info.channel()].end = _position._playPos;
// Go to the start of the loop // Go to the start of the loop
_position._play_pos = _loops[info.channel()].start; _position._playPos = _loops[info.channel()].start;
} }
} else { } else {
if (_loops[info.channel()].timer) if (_loops[info.channel()].timer)
_position._play_pos = _loops[info.channel()].start; _position._playPos = _loops[info.channel()].start;
--_loops[info.channel()].timer; --_loops[info.channel()].timer;
} }
} }
@ -141,13 +141,13 @@ void MidiParser_S1D::parseNextEvent(EventInfo &info) {
break; break;
case 0xC: // program change case 0xC: // program change
info.basic.param1 = *_position._play_pos++; info.basic.param1 = *_position._playPos++;
info.basic.param2 = 0; info.basic.param2 = 0;
break; break;
case 0xD: // jump to loop end case 0xD: // jump to loop end
if (_loops[info.channel()].end) if (_loops[info.channel()].end)
_position._play_pos = _loops[info.channel()].end; _position._playPos = _loops[info.channel()].end;
// We need to read the next midi event here. Since we can not // We need to read the next midi event here. Since we can not
// safely pass this event to the MIDI event processing. // safely pass this event to the MIDI event processing.
@ -178,7 +178,7 @@ bool MidiParser_S1D::loadMusic(byte *data, uint32 size) {
pos += 1; pos += 1;
// And now we're at the actual data. Only one track. // And now we're at the actual data. Only one track.
_num_tracks = 1; _numTracks = 1;
_data = pos; _data = pos;
_tracks[0] = pos; _tracks[0] = pos;
@ -194,7 +194,7 @@ bool MidiParser_S1D::loadMusic(byte *data, uint32 size) {
void MidiParser_S1D::resetTracking() { void MidiParser_S1D::resetTracking() {
MidiParser::resetTracking(); MidiParser::resetTracking();
// The first event never contains any delta. // The first event never contains any delta.
_no_delta = true; _noDelta = true;
memset(_loops, 0, sizeof(_loops)); memset(_loops, 0, sizeof(_loops));
} }

View file

@ -91,20 +91,20 @@ public:
}; };
void MidiParser_MSC::parseMetaEvent(EventInfo &info) { void MidiParser_MSC::parseMetaEvent(EventInfo &info) {
uint8 type = read1(_position._play_pos); uint8 type = read1(_position._playPos);
uint8 len = read1(_position._play_pos); uint8 len = read1(_position._playPos);
info.ext.type = type; info.ext.type = type;
info.length = len; info.length = len;
info.ext.data = 0; info.ext.data = 0;
if (type == 0x51) { if (type == 0x51) {
info.ext.data = _position._play_pos; info.ext.data = _position._playPos;
} else { } else {
warning("unknown meta event 0x%02X", type); warning("unknown meta event 0x%02X", type);
info.ext.type = 0; info.ext.type = 0;
} }
_position._play_pos += len; _position._playPos += len;
} }
void MidiParser_MSC::parseMidiEvent(EventInfo &info) { void MidiParser_MSC::parseMidiEvent(EventInfo &info) {
@ -116,13 +116,13 @@ void MidiParser_MSC::parseMidiEvent(EventInfo &info) {
case 0xA: case 0xA:
case 0xB: case 0xB:
case 0xE: case 0xE:
info.basic.param1 = read1(_position._play_pos); info.basic.param1 = read1(_position._playPos);
info.basic.param2 = read1(_position._play_pos); info.basic.param2 = read1(_position._playPos);
break; break;
case 0xC: case 0xC:
case 0xD: case 0xD:
info.basic.param1 = read1(_position._play_pos); info.basic.param1 = read1(_position._playPos);
info.basic.param2 = 0; info.basic.param2 = 0;
break; break;
@ -135,9 +135,9 @@ void MidiParser_MSC::parseMidiEvent(EventInfo &info) {
} }
void MidiParser_MSC::parseNextEvent(EventInfo &info) { void MidiParser_MSC::parseNextEvent(EventInfo &info) {
info.start = _position._play_pos; info.start = _position._playPos;
if (_position._play_pos >= _trackEnd) { if (_position._playPos >= _trackEnd) {
// fake an end-of-track meta event // fake an end-of-track meta event
info.delta = 0; info.delta = 0;
info.event = 0xFF; info.event = 0xFF;
@ -146,8 +146,8 @@ void MidiParser_MSC::parseNextEvent(EventInfo &info) {
return; return;
} }
info.delta = readVLQ(_position._play_pos); info.delta = readVLQ(_position._playPos);
info.event = read1(_position._play_pos); info.event = read1(_position._playPos);
if (info.event == 0xFF) { if (info.event == 0xFF) {
parseMetaEvent(info); parseMetaEvent(info);
@ -155,7 +155,7 @@ void MidiParser_MSC::parseNextEvent(EventInfo &info) {
} }
if (info.event < 0x80) { if (info.event < 0x80) {
_position._play_pos--; _position._playPos--;
info.event = _lastEvent; info.event = _lastEvent;
} }
@ -185,7 +185,7 @@ bool MidiParser_MSC::loadMusic(byte *data, uint32 size) {
_lastEvent = 0; _lastEvent = 0;
_trackEnd = data + size; _trackEnd = data + size;
_num_tracks = 1; _numTracks = 1;
_tracks[0] = pos; _tracks[0] = pos;
setTempo(500000); setTempo(500000);

View file

@ -98,7 +98,7 @@ bool MidiParser_SCI::loadMusic(SoundResource::Track *track, MusicEntry *psnd, in
midiMixChannels(); midiMixChannels();
} }
_num_tracks = 1; _numTracks = 1;
_tracks[0] = _mixedData; _tracks[0] = _mixedData;
if (_pSnd) if (_pSnd)
setTrack(0); setTrack(0);
@ -144,7 +144,7 @@ byte *MidiParser_SCI::midiMixChannels() {
_mixedData = outData; _mixedData = outData;
long ticker = 0; long ticker = 0;
byte channelNr, curDelta; byte channelNr, curDelta;
byte midiCommand = 0, midiParam, global_prev = 0; byte midiCommand = 0, midiParam, globalPrev = 0;
long newDelta; long newDelta;
SoundResource::Channel *channel; SoundResource::Channel *channel;
@ -190,13 +190,13 @@ byte *MidiParser_SCI::midiMixChannels() {
byte midiChannel = midiCommand & 0xF; byte midiChannel = midiCommand & 0xF;
_channelUsed[midiChannel] = true; _channelUsed[midiChannel] = true;
if (midiCommand != global_prev) if (midiCommand != globalPrev)
*outData++ = midiCommand; *outData++ = midiCommand;
*outData++ = midiParam; *outData++ = midiParam;
if (nMidiParams[(midiCommand >> 4) - 8] == 2) if (nMidiParams[(midiCommand >> 4) - 8] == 2)
*outData++ = channel->data[channel->curPos++]; *outData++ = channel->data[channel->curPos++];
channel->prev = midiCommand; channel->prev = midiCommand;
global_prev = midiCommand; globalPrev = midiCommand;
} }
} }
@ -372,8 +372,8 @@ void MidiParser_SCI::unloadMusic() {
resetTracking(); resetTracking();
allNotesOff(); allNotesOff();
} }
_num_tracks = 0; _numTracks = 0;
_active_track = 255; _activeTrack = 255;
_resetOnPause = false; _resetOnPause = false;
if (_mixedData) { if (_mixedData) {
@ -454,26 +454,26 @@ void MidiParser_SCI::parseNextEvent(EventInfo &info) {
debugC(4, kDebugLevelSound, "signal %04x", _signalToSet); debugC(4, kDebugLevelSound, "signal %04x", _signalToSet);
} }
info.start = _position._play_pos; info.start = _position._playPos;
info.delta = 0; info.delta = 0;
while (*_position._play_pos == 0xF8) { while (*_position._playPos == 0xF8) {
info.delta += 240; info.delta += 240;
_position._play_pos++; _position._playPos++;
} }
info.delta += *(_position._play_pos++); info.delta += *(_position._playPos++);
// Process the next info. // Process the next info.
if ((_position._play_pos[0] & 0xF0) >= 0x80) if ((_position._playPos[0] & 0xF0) >= 0x80)
info.event = *(_position._play_pos++); info.event = *(_position._playPos++);
else else
info.event = _position._running_status; info.event = _position._runningStatus;
if (info.event < 0x80) if (info.event < 0x80)
return; return;
_position._running_status = info.event; _position._runningStatus = info.event;
switch (info.command()) { switch (info.command()) {
case 0xC: case 0xC:
info.basic.param1 = *(_position._play_pos++); info.basic.param1 = *(_position._playPos++);
info.basic.param2 = 0; info.basic.param2 = 0;
if (info.channel() == 0xF) {// SCI special case if (info.channel() == 0xF) {// SCI special case
if (info.basic.param1 != kSetSignalLoop) { if (info.basic.param1 != kSetSignalLoop) {
@ -488,23 +488,23 @@ void MidiParser_SCI::parseNextEvent(EventInfo &info) {
// in glitches (e.g. the intro of LB1 Amiga gets stuck - bug // in glitches (e.g. the intro of LB1 Amiga gets stuck - bug
// #3297883). Refer to MusicEntry::setSignal() in sound/music.cpp. // #3297883). Refer to MusicEntry::setSignal() in sound/music.cpp.
if (_soundVersion <= SCI_VERSION_0_LATE || if (_soundVersion <= SCI_VERSION_0_LATE ||
_position._play_tick || info.delta) { _position._playTick || info.delta) {
_signalSet = true; _signalSet = true;
_signalToSet = info.basic.param1; _signalToSet = info.basic.param1;
} }
} else { } else {
_loopTick = _position._play_tick + info.delta; _loopTick = _position._playTick + info.delta;
} }
} }
break; break;
case 0xD: case 0xD:
info.basic.param1 = *(_position._play_pos++); info.basic.param1 = *(_position._playPos++);
info.basic.param2 = 0; info.basic.param2 = 0;
break; break;
case 0xB: case 0xB:
info.basic.param1 = *(_position._play_pos++); info.basic.param1 = *(_position._playPos++);
info.basic.param2 = *(_position._play_pos++); info.basic.param2 = *(_position._playPos++);
// Reference for some events: // Reference for some events:
// http://wiki.scummvm.org/index.php/SCI/Specifications/Sound/SCI0_Resource_Format#Status_Reference // http://wiki.scummvm.org/index.php/SCI/Specifications/Sound/SCI0_Resource_Format#Status_Reference
@ -588,8 +588,8 @@ void MidiParser_SCI::parseNextEvent(EventInfo &info) {
case 0x9: case 0x9:
case 0xA: case 0xA:
case 0xE: case 0xE:
info.basic.param1 = *(_position._play_pos++); info.basic.param1 = *(_position._playPos++);
info.basic.param2 = *(_position._play_pos++); info.basic.param2 = *(_position._playPos++);
if (info.command() == 0x9 && info.basic.param2 == 0) if (info.command() == 0x9 && info.basic.param2 == 0)
info.event = info.channel() | 0x80; info.event = info.channel() | 0x80;
info.length = 0; info.length = 0;
@ -598,12 +598,12 @@ void MidiParser_SCI::parseNextEvent(EventInfo &info) {
case 0xF: // System Common, Meta or SysEx event case 0xF: // System Common, Meta or SysEx event
switch (info.event & 0x0F) { switch (info.event & 0x0F) {
case 0x2: // Song Position Pointer case 0x2: // Song Position Pointer
info.basic.param1 = *(_position._play_pos++); info.basic.param1 = *(_position._playPos++);
info.basic.param2 = *(_position._play_pos++); info.basic.param2 = *(_position._playPos++);
break; break;
case 0x3: // Song Select case 0x3: // Song Select
info.basic.param1 = *(_position._play_pos++); info.basic.param1 = *(_position._playPos++);
info.basic.param2 = 0; info.basic.param2 = 0;
break; break;
@ -617,16 +617,16 @@ void MidiParser_SCI::parseNextEvent(EventInfo &info) {
break; break;
case 0x0: // SysEx case 0x0: // SysEx
info.length = readVLQ(_position._play_pos); info.length = readVLQ(_position._playPos);
info.ext.data = _position._play_pos; info.ext.data = _position._playPos;
_position._play_pos += info.length; _position._playPos += info.length;
break; break;
case 0xF: // META event case 0xF: // META event
info.ext.type = *(_position._play_pos++); info.ext.type = *(_position._playPos++);
info.length = readVLQ(_position._play_pos); info.length = readVLQ(_position._playPos);
info.ext.data = _position._play_pos; info.ext.data = _position._playPos;
_position._play_pos += info.length; _position._playPos += info.length;
if (info.ext.type == 0x2F) {// end of track reached if (info.ext.type == 0x2F) {// end of track reached
if (_pSnd->loop) if (_pSnd->loop)
_pSnd->loop--; _pSnd->loop--;
@ -677,21 +677,21 @@ void MidiParser_SCI::allNotesOff() {
// Turn off all active notes // Turn off all active notes
for (i = 0; i < 128; ++i) { for (i = 0; i < 128; ++i) {
for (j = 0; j < 16; ++j) { for (j = 0; j < 16; ++j) {
if ((_active_notes[i] & (1 << j)) && (_channelRemap[j] != -1)){ if ((_activeNotes[i] & (1 << j)) && (_channelRemap[j] != -1)){
sendToDriver(0x80 | j, i, 0); sendToDriver(0x80 | j, i, 0);
} }
} }
} }
// Turn off all hanging notes // Turn off all hanging notes
for (i = 0; i < ARRAYSIZE(_hanging_notes); i++) { for (i = 0; i < ARRAYSIZE(_hangingNotes); i++) {
byte midiChannel = _hanging_notes[i].channel; byte midiChannel = _hangingNotes[i].channel;
if ((_hanging_notes[i].time_left) && (_channelRemap[midiChannel] != -1)) { if ((_hangingNotes[i].timeLeft) && (_channelRemap[midiChannel] != -1)) {
sendToDriver(0x80 | midiChannel, _hanging_notes[i].note, 0); sendToDriver(0x80 | midiChannel, _hangingNotes[i].note, 0);
_hanging_notes[i].time_left = 0; _hangingNotes[i].timeLeft = 0;
} }
} }
_hanging_notes_count = 0; _hangingNotesCount = 0;
// To be sure, send an "All Note Off" event (but not all MIDI devices // To be sure, send an "All Note Off" event (but not all MIDI devices
// support this...). // support this...).
@ -703,7 +703,7 @@ void MidiParser_SCI::allNotesOff() {
} }
} }
memset(_active_notes, 0, sizeof(_active_notes)); memset(_activeNotes, 0, sizeof(_activeNotes));
} }
void MidiParser_SCI::setMasterVolume(byte masterVolume) { void MidiParser_SCI::setMasterVolume(byte masterVolume) {

View file

@ -65,7 +65,7 @@ public:
void setMasterVolume(byte masterVolume); void setMasterVolume(byte masterVolume);
void setVolume(byte volume); void setVolume(byte volume);
void stop() { void stop() {
_abort_parse = true; _abortParse = true;
allNotesOff(); allNotesOff();
} }
void pause() { void pause() {

View file

@ -62,13 +62,13 @@ void MidiParser_RO::parseNextEvent (EventInfo &info) {
info.delta = 0; info.delta = 0;
do { do {
info.start = _position._play_pos; info.start = _position._playPos;
info.event = *(_position._play_pos++); info.event = *(_position._playPos++);
if (info.command() == 0xA) { if (info.command() == 0xA) {
++_lastMarkerCount; ++_lastMarkerCount;
info.event = 0xF0; info.event = 0xF0;
} else if (info.event == 0xF0 || info.event == 0xF1) { } else if (info.event == 0xF0 || info.event == 0xF1) {
byte delay = *(_position._play_pos++); byte delay = *(_position._playPos++);
info.delta += delay; info.delta += delay;
if (info.event == 0xF1) { if (info.event == 0xF1) {
// This event is, as far as we have been able // This event is, as far as we have been able
@ -95,16 +95,16 @@ void MidiParser_RO::parseNextEvent (EventInfo &info) {
if (info.event < 0x80) if (info.event < 0x80)
return; return;
_position._running_status = info.event; _position._runningStatus = info.event;
switch (info.command()) { switch (info.command()) {
case 0xC: case 0xC:
info.basic.param1 = *(_position._play_pos++); info.basic.param1 = *(_position._playPos++);
info.basic.param2 = 0; info.basic.param2 = 0;
break; break;
case 0x8: case 0x9: case 0xB: case 0x8: case 0x9: case 0xB:
info.basic.param1 = *(_position._play_pos++); info.basic.param1 = *(_position._playPos++);
info.basic.param2 = *(_position._play_pos++); info.basic.param2 = *(_position._playPos++);
if (info.command() == 0x9 && info.basic.param2 == 0) if (info.command() == 0x9 && info.basic.param2 == 0)
info.event = info.channel() | 0x80; info.event = info.channel() | 0x80;
info.length = 0; info.length = 0;
@ -133,7 +133,7 @@ bool MidiParser_RO::loadMusic (byte *data, uint32 size) {
return false; return false;
} }
_num_tracks = 1; _numTracks = 1;
_ppqn = 120; _ppqn = 120;
_tracks[0] = pos + 2; _tracks[0] = pos + 2;
_markerCount = _lastMarkerCount = 0; _markerCount = _lastMarkerCount = 0;