Class: Mass::Note
Overview
Represents a single note in the pattern.
Constant Summary collapse
- VELOCITIES =
Dictionary of velocity values from a given
expression. { ff: 127, mf: 117, f: 107, mp: 97, p: 85, pp: 75 }
- ON =
Hex value for sending to
UniMIDIthat signals when this note should begin playing. 0x90- OFF =
Hex value for sending to
UniMIDIthat signals when this note should cease playing. 0x80
Instance Attribute Summary collapse
-
#bpm ⇒ Object
readonly
BPM passed in from the sequence.
-
#duration ⇒ Object
readonly
The given duration value divided by the BPM of the current song.
-
#expression ⇒ Object
readonly
Expression value of the note, e.g.
-
#midi ⇒ Object
readonly
MIDI output object.
-
#pitch ⇒ Integer
readonly
This note as expressed in a MIDI pitch value.
-
#value ⇒ Object
readonly
Rhythmic duration value for this note.
Instance Method Summary collapse
-
#initialize(value: 1, pitch: nil, exp: :mp, midi: nil, bpm: 100) ⇒ Note
constructor
A new instance of Note.
-
#play ⇒ Object
Play the current note through the
UniMIDIoutput. -
#to_velocity ⇒ Integer
This note as expressed in a MIDI velocity value.
Constructor Details
#initialize(value: 1, pitch: nil, exp: :mp, midi: nil, bpm: 100) ⇒ Note
Returns a new instance of Note.
79 80 81 82 83 84 85 86 |
# File 'lib/mass/note.rb', line 79 def initialize(value: 1, pitch: nil, exp: :mp, midi: nil, bpm: 100) @value = value @name = pitch @pitch = Pitch.find pitch @expression = exp @midi = midi @bpm = bpm end |
Instance Attribute Details
#bpm ⇒ Object (readonly)
BPM passed in from the sequence.
61 62 63 |
# File 'lib/mass/note.rb', line 61 def bpm @bpm end |
#duration ⇒ Object (readonly)
The given duration value divided by the BPM of the current song.
24 25 26 |
# File 'lib/mass/note.rb', line 24 def duration @duration end |
#expression ⇒ Object (readonly)
Expression value of the note, e.g. ‘:ff’. This can optionally be given as an Integer for maximum velocity control and is simply output as the velocity.
The following expression values are supported:
-
:ff
-
:mf
-
:f
-
:mp
-
:p
-
:pp
40 41 42 |
# File 'lib/mass/note.rb', line 40 def expression @expression end |
#midi ⇒ Object (readonly)
MIDI output object.
45 46 47 |
# File 'lib/mass/note.rb', line 45 def midi @midi end |
#pitch ⇒ Integer (readonly)
This note as expressed in a MIDI pitch value.
51 52 53 |
# File 'lib/mass/note.rb', line 51 def pitch @pitch end |
#value ⇒ Object (readonly)
Rhythmic duration value for this note.
56 57 58 |
# File 'lib/mass/note.rb', line 56 def value @value end |
Instance Method Details
#play ⇒ Object
Play the current note through the UniMIDI output.
107 108 109 110 111 |
# File 'lib/mass/note.rb', line 107 def play midi.puts ON, to_midi, to_velocity unless pitch.nil? sleep duration midi.puts OFF, to_midi, to_velocity unless pitch.nil? end |
#to_velocity ⇒ Integer
This note as expressed in a MIDI velocity value.
96 97 98 |
# File 'lib/mass/note.rb', line 96 def to_velocity VELOCITIES[expression] || expression end |