Class: Mass::Note

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/mass/note.rb

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 UniMIDI that signals when this note should begin playing.

0x90
OFF =

Hex value for sending to UniMIDI that signals when this note should cease playing.

0x80

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value: 1, pitch: nil, exp: :mp, midi: nil, bpm: 100) ⇒ Note

Returns a new instance of Note.

Parameters:

  • value (Integer) (defaults to: 1)
  • pitch (String) (defaults to: nil)
  • exp (Symbol | Integer) (defaults to: :mp)
    • Can be expressed as either

  • midi (UniMIDI::Output) (defaults to: nil)


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

#bpmObject (readonly)

BPM passed in from the sequence.



61
62
63
# File 'lib/mass/note.rb', line 61

def bpm
  @bpm
end

#durationObject (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

#expressionObject (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

#midiObject (readonly)

MIDI output object.



45
46
47
# File 'lib/mass/note.rb', line 45

def midi
  @midi
end

#pitchInteger (readonly)

This note as expressed in a MIDI pitch value.

Returns:

  • (Integer)


51
52
53
# File 'lib/mass/note.rb', line 51

def pitch
  @pitch
end

#valueObject (readonly)

Rhythmic duration value for this note.



56
57
58
# File 'lib/mass/note.rb', line 56

def value
  @value
end

Instance Method Details

#playObject

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_velocityInteger

This note as expressed in a MIDI velocity value.

Returns:

  • (Integer)


96
97
98
# File 'lib/mass/note.rb', line 96

def to_velocity
  VELOCITIES[expression] || expression
end