@@ -293,64 +293,12 @@ class SaveInterface {
293293 * @instance
294294 */
295295 afterSaveMIDI ( ) {
296+ const instrumentMIDI = getMidiInstrument ( ) ;
297+ const drumMIDI = getMidiDrum ( ) ;
296298 const generateMidi = ( data ) => {
297299 const normalizeNote = ( note ) => {
298300 return note . replace ( "♯" , "#" ) . replace ( "♭" , "b" ) ;
299301 } ;
300- const MIDI_INSTRUMENTS = {
301- default : 0 , // Acoustic Grand Piano
302- piano : 0 ,
303- violin : 40 ,
304- viola : 41 ,
305- cello : 42 ,
306- "double bass" : 43 ,
307- bass : 32 ,
308- sitar : 104 ,
309- guitar : 24 ,
310- "acoustic guitar" : 25 ,
311- "electric guitar" : 27 ,
312- flute : 73 ,
313- clarinet : 71 ,
314- saxophone : 65 ,
315- tuba : 58 ,
316- trumpet : 56 ,
317- oboe : 68 ,
318- trombone : 57 ,
319- banjo : 105 ,
320- koto : 107 ,
321- dulcimer : 15 ,
322- bassoon : 70 ,
323- celeste : 8 ,
324- xylophone : 13 ,
325- "electronic synth" : 81 ,
326- sine : 81 , // Approximate with Lead 2 (Sawtooth)
327- square : 80 ,
328- sawtooth : 81 ,
329- triangle : 81 , // Approximate with Lead 2 (Sawtooth)
330- vibraphone : 11
331- } ;
332-
333- const DRUM_MIDI_MAP = {
334- "snare drum" : 38 ,
335- "kick drum" : 36 ,
336- "tom tom" : 41 ,
337- "floor tom tom" : 43 ,
338- "cup drum" : 47 , // Closest: Low-Mid Tom
339- "darbuka drum" : 50 , // Closest: High Tom
340- "japanese drum" : 56 , // Closest: Cowbell or Tambourine
341- "hi hat" : 42 ,
342- "ride bell" : 53 ,
343- "cow bell" : 56 ,
344- "triangle bell" : 81 ,
345- "finger cymbals" : 69 , // Closest: Open Hi-Hat
346- "chime" : 82 , // Closest: Shaker
347- "gong" : 52 , // Closest: Chinese Cymbal
348- "clang" : 55 , // Closest: Splash Cymbal
349- "crash" : 49 ,
350- "clap" : 39 ,
351- "slap" : 40 ,
352- "raindrop" : 88 // Custom mapping (not in GM), can use melodic notes
353- } ;
354302
355303 const midi = new Midi ( ) ;
356304 midi . header . ticksPerBeat = 480 ;
@@ -379,7 +327,7 @@ class SaveInterface {
379327
380328 const drumTrack = trackMap . get ( drum ) ;
381329
382- const midiNumber = DRUM_MIDI_MAP [ drum ] || 36 ; // default to Bass Drum
330+ const midiNumber = drumMIDI [ drum ] || 36 ; // default to Bass Drum
383331 drumTrack . addNote ( {
384332 midi : midiNumber ,
385333 time : globalTime ,
@@ -391,7 +339,7 @@ class SaveInterface {
391339 if ( ! trackMap . has ( instrument ) ) {
392340 const instrumentTrack = midi . addTrack ( ) ;
393341 instrumentTrack . name = `Track ${ parseInt ( blockIndex ) + 1 } - ${ instrument } ` ;
394- instrumentTrack . instrument . number = MIDI_INSTRUMENTS [ instrument ] ?? MIDI_INSTRUMENTS [ "default" ] ;
342+ instrumentTrack . instrument . number = instrumentMIDI [ instrument ] ?? instrumentMIDI [ "default" ] ;
395343 trackMap . set ( instrument , instrumentTrack ) ;
396344 }
397345
0 commit comments