class MIDI::KeySig
Container for key signature events
Public Class Methods
new(sharpflat, is_minor, delta_time = 0)
click to toggle source
Constructor
Calls superclass method
MIDI::MetaEvent::new
# File lib/midilib/event.rb, line 596 def initialize(sharpflat, is_minor, delta_time = 0) super(META_KEY_SIG, [sharpflat, is_minor], delta_time) end
Public Instance Methods
data_as_bytes()
click to toggle source
Returns the complete event as stored in the sequence
# File lib/midilib/event.rb, line 601 def data_as_bytes data = [] data << @status data << @meta_type data << 2 data << @data[0] data << (@data[1] ? 1 : 0) end
major_key?()
click to toggle source
Returns true if it’s a major key, false if minor key
# File lib/midilib/event.rb, line 616 def major_key? !@data[1] end
minor_key?()
click to toggle source
Returns true if it’s a minor key, false if major key
# File lib/midilib/event.rb, line 611 def minor_key? @data[1] end
sharpflat()
click to toggle source
Returns the number of sharps/flats in the key sig. Negative for flats.
# File lib/midilib/event.rb, line 621 def sharpflat @data[0] > 7 ? @data[0] - 256 : @data[0] end
to_code()
click to toggle source
Returns the key signature as a code. Example: “Ab” for “key sig A flat major”
# File lib/midilib/event.rb, line 637 def to_code if minor_key? minorkey_codes[sharpflat + 7] else majorkey_codes[sharpflat + 7] end end
to_s()
click to toggle source
Returns the key signature as a text string. Example: “key sig A flat major”
# File lib/midilib/event.rb, line 627 def to_s if minor_key? "key sig #{minorkeys[sharpflat + 7]} minor" else "key sig #{majorkeys[sharpflat + 7]} major" end end
Private Instance Methods
majorkey_codes()
click to toggle source
# File lib/midilib/event.rb, line 657 def majorkey_codes @majorkeys_codes ||= ['Cb', 'Gb', 'Db', 'Ab', 'Eb', 'Bb', 'F', 'C', 'G', 'D', 'A', 'E', 'B', 'F#', 'C#'] end
majorkeys()
click to toggle source
# File lib/midilib/event.rb, line 647 def majorkeys @majorkeys ||= ['C flat', 'G flat', 'D flat', 'A flat', 'E flat', 'B flat', 'F', 'C', 'G', 'D', 'A', 'E', 'B', 'F#', 'C#'] end
minorkey_codes()
click to toggle source
# File lib/midilib/event.rb, line 662 def minorkey_codes @minorkeys_codes ||= ['Abm', 'Ebm', 'Bbm', 'Fm', 'Cm', 'Gm', 'Dm', 'Am', 'Em', 'Bm', 'F#m', 'C#m', 'G#m', 'D#m', 'A#m'] end
minorkeys()
click to toggle source
# File lib/midilib/event.rb, line 652 def minorkeys @minorkeys ||= ['a flat', 'e flat', 'b flat', 'f', 'c', 'g', 'd', 'a', 'e', 'b', 'f#', 'c#', 'g#', 'd#', 'a#'] end