Class: MIDI::Array
- Inherits:
-
Array
- Object
- Array
- MIDI::Array
- Defined in:
- lib/midilib/track.rb
Overview
This is taken from github.com/adamjmurray/cosy/blob/master/lib/cosy/helper/midi_file_renderer_helper.rb with permission from Adam Murray, who originally suggested this fix. See wiki.github.com/adamjmurray/cosy/midilib-notes for details. First we need to add some API infrastructure:
Direct Known Subclasses
Instance Method Summary collapse
-
#mergesort(&cmp) ⇒ Object
A stable sorting algorithm that maintains the relative order of equal elements.
Instance Method Details
#mergesort(&cmp) ⇒ Object
A stable sorting algorithm that maintains the relative order of equal elements
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/midilib/track.rb', line 14 def mergesort(&cmp) if cmp == nil cmp = lambda { |a, b| a <=> b } end if size <= 1 self.dup else halves = split.map { |half| half.mergesort(&cmp) } merge(*halves, &cmp) end end |