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