Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use channel 10 for percussion #187

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions generator/ruby/soundfont_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
# This script will generate MIDI.js-compatible instrument JS files for
# all instruments in the below array. Add or remove as necessary.
INSTRUMENTS = [
-1, # Percussion (channel 10)
0 # Acoustic Grand Piano
];
# INSTRUMENTS = [
# -1, # Percussion (channel 10)
# 0, # Acoustic Grand Piano
# 24, # Acoustic Guitar (nylon)
# 25, # Acoustic Guitar (steel)
Expand Down Expand Up @@ -64,7 +66,11 @@

# Display instrument names.
INSTRUMENTS.each do |i|
puts " #{i}: " + MIDI::GM_PATCH_NAMES[i]
Comment on lines 66 to -67

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test

if i == -1
puts " percussion (MIDI channel 10)"
else
puts " #{i}: " + MIDI::GM_PATCH_NAMES[i]
end
end

puts
Expand Down Expand Up @@ -137,11 +143,16 @@ def generate_midi(program, note_value, file)
include MIDI
seq = Sequence.new()
track = Track.new(seq)
channel = 0
if program == -1
channel = 9
program = 0
end

seq.tracks << track
track.events << ProgramChange.new(0, Integer(program))
track.events << NoteOn.new(0, note_value, VELOCITY, 0) # channel, note, velocity, delta
track.events << NoteOff.new(0, note_value, VELOCITY, DURATION)
track.events << ProgramChange.new(channel, Integer(program))
track.events << NoteOn.new(channel, note_value, VELOCITY, 0) # channel, note, velocity, delta
track.events << NoteOff.new(channel, note_value, VELOCITY, DURATION)

File.open(file, 'wb') { | file | seq.write(file) }
end
Expand Down Expand Up @@ -183,7 +194,11 @@ def base64js(note, file, type)

def generate_audio(program)
include MIDI
instrument = GM_PATCH_NAMES[program]
if program == -1
instrument = "percussion"
else
instrument = GM_PATCH_NAMES[program]
end
instrument_key = instrument.downcase.gsub(/[^a-z0-9 ]/, "").gsub(/\s+/, "_")

puts "Generating audio for: " + instrument + "(#{instrument_key})"
Expand Down
4 changes: 3 additions & 1 deletion js/midi/gm.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
'Synth Effects': ['97 FX 1 (rain)', '98 FX 2 (soundtrack)', '99 FX 3 (crystal)', '100 FX 4 (atmosphere)', '101 FX 5 (brightness)', '102 FX 6 (goblins)', '103 FX 7 (echoes)', '104 FX 8 (sci-fi)'],
'Ethnic': ['105 Sitar', '106 Banjo', '107 Shamisen', '108 Koto', '109 Kalimba', '110 Bagpipe', '111 Fiddle', '112 Shanai'],
'Percussive': ['113 Tinkle Bell', '114 Agogo', '115 Steel Drums', '116 Woodblock', '117 Taiko Drum', '118 Melodic Tom', '119 Synth Drum'],
'Sound effects': ['120 Reverse Cymbal', '121 Guitar Fret Noise', '122 Breath Noise', '123 Seashore', '124 Bird Tweet', '125 Telephone Ring', '126 Helicopter', '127 Applause', '128 Gunshot']
'Sound effects': ['120 Reverse Cymbal', '121 Guitar Fret Noise', '122 Breath Noise', '123 Seashore', '124 Bird Tweet', '125 Telephone Ring', '126 Helicopter', '127 Applause', '128 Gunshot'],
'Percussion': ['0 Percussion'] // not really GM but convenient hack
});

/* get/setInstrument
Expand Down Expand Up @@ -138,6 +139,7 @@
solo: false
};
}
channels[9].instrument = -1; // channel 10 is percussion
return channels;
})();

Expand Down
4 changes: 2 additions & 2 deletions js/midi/plugin.webaudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
var notes = root.keyToNote;
for (var key in notes) urls.push(key);
///
var waitForEnd = function(instrument) {
var waitForEnd = function() {
for (var key in bufferPending) { // has pending items
if (bufferPending[key]) return;
}
Expand All @@ -259,7 +259,7 @@
var percent = index / 87;
// console.log(MIDI.GM.byId[instrumentId], 'processing: ', percent);
soundfont.isLoaded = true;
waitForEnd(instrument);
waitForEnd();
}
}, function(err) {
// console.log(err);
Expand Down