Class: MIDI::KeySig
Overview
Container for key signature events
Instance Attribute Summary
Attributes inherited from MetaEvent
Attributes inherited from Event
#delta_time, #print_channel_numbers_from_one, #print_decimal_numbers, #print_note_names, #status, #time_from_start
Instance Method Summary collapse
-
#data_as_bytes ⇒ Object
Returns the complete event as stored in the sequence.
-
#initialize(sharpflat, is_minor, delta_time = 0) ⇒ KeySig
constructor
Constructor.
-
#major_key? ⇒ Boolean
Returns true if it’s a major key, false if minor key.
-
#minor_key? ⇒ Boolean
Returns true if it’s a minor key, false if major key.
-
#sharpflat ⇒ Object
Returns the number of sharps/flats in the key sig.
-
#to_code ⇒ Object
Returns the key signature as a code.
-
#to_s ⇒ Object
Returns the key signature as a text string.
Methods inherited from MetaEvent
bytes_as_str, #data_as_str, str_as_bytes
Methods inherited from Event
#<=>, #channel_to_s, #number_to_s, #quantize_to
Constructor Details
#initialize(sharpflat, is_minor, delta_time = 0) ⇒ KeySig
Constructor
596 597 598 |
# 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 |
Instance Method Details
#data_as_bytes ⇒ Object
Returns the complete event as stored in the sequence
601 602 603 604 605 606 607 608 |
# 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? ⇒ Boolean
Returns true if it’s a major key, false if minor key
616 617 618 |
# File 'lib/midilib/event.rb', line 616 def major_key? !@data[1] end |
#minor_key? ⇒ Boolean
Returns true if it’s a minor key, false if major key
611 612 613 |
# File 'lib/midilib/event.rb', line 611 def minor_key? @data[1] end |
#sharpflat ⇒ Object
Returns the number of sharps/flats in the key sig. Negative for flats.
621 622 623 |
# File 'lib/midilib/event.rb', line 621 def sharpflat @data[0] > 7 ? @data[0] - 256 : @data[0] end |
#to_code ⇒ Object
Returns the key signature as a code. Example: “Ab” for “key sig A flat major”
637 638 639 640 641 642 643 |
# 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 ⇒ Object
Returns the key signature as a text string. Example: “key sig A flat major”
627 628 629 630 631 632 633 |
# 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 |