Class: Music::Performance::MidiUtil
- Inherits:
-
Object
- Object
- Music::Performance::MidiUtil
- Defined in:
- lib/music-performance/arrangement/midi/midi_util.rb
Constant Summary collapse
- QUARTER =
Rational(1,4)
- MIDI_NOTENUMS =
Hash[ (0..127).map do |note_num| [ p0.transpose(note_num), note_num ]
Class Method Summary collapse
- .delta(duration, ppqn) ⇒ Object
- .dynamic_to_volume(dynamic) ⇒ Object
- .note_velocity(accented) ⇒ Object
- .pitch_to_notenum(pitch) ⇒ Object
- .usec_per_qnote(notes_per_sec) ⇒ Object
Class Method Details
.delta(duration, ppqn) ⇒ Object
6 7 8 9 |
# File 'lib/music-performance/arrangement/midi/midi_util.rb', line 6 def self.delta duration, ppqn pulses = (duration / QUARTER) * ppqn return pulses.round end |
.dynamic_to_volume(dynamic) ⇒ Object
28 29 30 |
# File 'lib/music-performance/arrangement/midi/midi_util.rb', line 28 def self.dynamic_to_volume dynamic (dynamic * 127).round end |
.note_velocity(accented) ⇒ Object
32 33 34 |
# File 'lib/music-performance/arrangement/midi/midi_util.rb', line 32 def self.note_velocity(accented) accented ? 112 : 70 end |
.pitch_to_notenum(pitch) ⇒ Object
24 25 26 |
# File 'lib/music-performance/arrangement/midi/midi_util.rb', line 24 def self.pitch_to_notenum pitch MIDI_NOTENUMS[pitch.round] end |
.usec_per_qnote(notes_per_sec) ⇒ Object
11 12 13 14 15 |
# File 'lib/music-performance/arrangement/midi/midi_util.rb', line 11 def self.usec_per_qnote notes_per_sec spn = 1.0 / notes_per_sec spqn = spn / 4.0 return (spqn * 1_000_000).to_i end |