shithub: choc

Download patch

ref: 61b2e3d2b8b6b2b6ddf8b92842ac4bcf47945160
parent: 1d045ed19c58abff063ac69db24a2e73d62ef530
author: Simon Howard <[email protected]>
date: Sun Aug 30 18:26:30 EDT 2009

Set the right instrument for percussion notes.

Subversion-branch: /branches/opl-branch
Subversion-revision: 1645

--- a/src/i_oplmusic.c
+++ b/src/i_oplmusic.c
@@ -656,8 +656,10 @@
 
 static void NoteOnEvent(opl_track_data_t *track, midi_event_t *event)
 {
+    genmidi_instr_t *instrument;
     opl_voice_t *voice;
     opl_channel_data_t *channel;
+    unsigned int note;
 
     printf("note on: channel %i, %i, %i\n",
            event->data.channel.channel,
@@ -667,7 +669,24 @@
     // The channel.
 
     channel = &track->channels[event->data.channel.channel];
+    note = event->data.channel.param1;
 
+    // Percussion channel (10) is treated differently to normal notes.
+
+    if (event->data.channel.channel == 9)
+    {
+        if (note < 35 || note > 81)
+        {
+            return;
+        }
+
+        instrument = &percussion_instrs[note - 35];
+    }
+    else
+    {
+        instrument = channel->instrument;
+    }
+
     // Find a voice to use for this new note.
 
     voice = GetFreeVoice();
@@ -679,7 +698,7 @@
 
     // Program the voice with the instrument data:
 
-    SetVoiceInstrument(voice, &channel->instrument->opl2_voice);
+    SetVoiceInstrument(voice, &instrument->opl2_voice);
 
     // TODO: Set the volume level.
 
@@ -686,12 +705,10 @@
     WriteRegister(OPL_REGS_LEVEL + voice->op2,
                   volume_mapping_table[channel->volume]);
 
-    printf("volume = %i\n", channel->volume);
-
     // Play the note.
 
     voice->channel = channel;
-    voice->note = event->data.channel.param1;
+    voice->note = note;
 
     // Write the frequency value to turn the note on.
 
@@ -840,7 +857,7 @@
     // Default is 120 bpm.
     // TODO: this is wrong
 
-    track->us_per_beat = 500 * 1000 * 200;
+    track->us_per_beat = 500 * 1000 * 260;
 
     for (i=0; i<MIDI_CHANNELS_PER_TRACK; ++i)
     {