class Mass::Note

Represents a single note in the pattern.

Constants

OFF

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

@type [Fixnum]

ON

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

@type [Fixnum]

VELOCITIES

Dictionary of velocity values from a given expression.

@type [Hash<Symbol>]

Attributes

bpm[R]

BPM passed in from the sequence.

@attr_reader [Integer]

duration[R]

Duration value of the note.

@attr_reader [Integer]

expression[R]

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

@attr_reader [Symbol | Integer]

midi[R]

MIDI output object.

@attr_reader [UniMIDI::Output]

pitch[R]

Pitch object used for figuring out the MIDI pitch value.

@attr_reader [Mass::Pitch]

value[R]

Rhythmic duration value for this note.

@attr_reader [Integer]

Public Class Methods

new(value: 1, pitch: nil, exp: :mp, midi: nil, bpm: 100) click to toggle source

@param [Integer] value @param [String] pitch @param [Symbol | Integer] exp - Can be expressed as either @param [UniMIDI::Output] midi

# 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

Public Instance Methods

play() click to toggle source

Play the current note through the UniMIDI output.

# 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() click to toggle source

This note as expressed in a MIDI velocity value.

@return [Integer]

# File lib/mass/note.rb, line 96
def to_velocity
  VELOCITIES[expression] || expression
end

Private Instance Methods

vpm() click to toggle source
# File lib/mass/note.rb, line 115
def vpm
  bpm / value
end