Class: Musicality::Score::Tempo

Inherits:
Musicality::Score show all
Defined in:
lib/musicality/notation/model/score.rb,
lib/musicality/composition/dsl/score_methods.rb,
lib/musicality/performance/midi/score_sequencing.rb,
lib/musicality/printing/lilypond/score_engraving.rb,
lib/musicality/notation/conversion/score_conversion.rb,
lib/musicality/performance/supercollider/score_conducting.rb

Overview

Tempo-based score with meter, bar lines, and a fixed pulse (beat).

Offsets and durations are based on note duration, but note duration is determined by the tempo, which can change.

Tempo values are in beats-per-minute.

Constant Summary

Constants inherited from Musicality::Score

DEFAULT_START_DYNAMIC

Constants included from Packable

Packable::PACKED_CLASS_KEY

Instance Attribute Summary collapse

Attributes inherited from Musicality::Score

#auditions, #composer, #key_changes, #parts, #program, #sections, #start_key, #title

Instance Method Summary collapse

Methods inherited from Musicality::Score

#audition, #clone, #collated?, #duration, #dynamic_change, #notes, #repeat, #section

Methods included from Validatable

#errors, #invalid?, #valid?, #validate

Methods included from Packable

#class_str, included, #init_params, #pack, pack_val, recover_class, unpack_val

Constructor Details

#initialize(start_tempo, tempo_changes: {}, start_meter: Meters::FOUR_FOUR, meter_changes: {}, parts: {}, program: [], title: nil, composer: nil, sections: {}, start_key: Keys::C_MAJOR, key_changes: {}, auditions: []) ⇒ Tempo

See Score#initialize for remaining kwargs



82
83
84
85
86
87
88
89
# File 'lib/musicality/notation/model/score.rb', line 82

def initialize start_tempo, tempo_changes: {}, start_meter: Meters::FOUR_FOUR, meter_changes: {}, parts: {}, program: [], title: nil, composer: nil, sections: {}, start_key: Keys::C_MAJOR, key_changes: {}, auditions: []
  @start_tempo = start_tempo
  @tempo_changes = tempo_changes
  @start_meter = start_meter
  @meter_changes = meter_changes

  super(parts: parts, program: program, title: title, composer: composer, sections: sections, start_key: start_key, key_changes: key_changes, auditions: auditions)
end

Instance Attribute Details

#meter_changesObject

Returns the value of attribute meter_changes.



79
80
81
# File 'lib/musicality/notation/model/score.rb', line 79

def meter_changes
  @meter_changes
end

#start_meterObject

Returns the value of attribute start_meter.



79
80
81
# File 'lib/musicality/notation/model/score.rb', line 79

def start_meter
  @start_meter
end

#start_tempoObject

Returns the value of attribute start_tempo.



79
80
81
# File 'lib/musicality/notation/model/score.rb', line 79

def start_tempo
  @start_tempo
end

#tempo_changesObject

Returns the value of attribute tempo_changes.



79
80
81
# File 'lib/musicality/notation/model/score.rb', line 79

def tempo_changes
  @tempo_changes
end

Instance Method Details

#==(other) ⇒ Object



99
100
101
102
103
104
105
# File 'lib/musicality/notation/model/score.rb', line 99

def ==(other)
  return super(other) &&
  @start_tempo == other.start_tempo &&
  @tempo_changes == other.tempo_changes
  @start_meter == other.start_meter &&
  @meter_changes == other.meter_changes
end

#beat_durationsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/musicality/notation/conversion/score_conversion.rb', line 11

def beat_durations
  bdurs = @meter_changes.map do |offset,change_or_meter|
    if change_or_meter.is_a? Meter
      [ offset, change_or_meter.beat_duration ]
    else
      [ offset, change_or_meter.end_value.beat_duration ]
    end
  end.sort
  
  if bdurs.empty? || bdurs[0][0] != 0
    bdurs.unshift([0.to_r,@start_meter.beat_duration])
  end

  return Hash[ bdurs ]
end

#check_methodsObject



91
92
93
# File 'lib/musicality/notation/model/score.rb', line 91

def check_methods
  super() + [:check_start_tempo, :check_tempo_changes, :check_start_meter, :check_meter_changes]
end

#key_change(new_key, offset: 0) ⇒ Object



79
80
81
# File 'lib/musicality/composition/dsl/score_methods.rb', line 79

def key_change new_key, offset: 0
  key_changes[self.duration + offset] = Change::Immediate.new(new_key)
end

#measure_duration(note_offset = self.duration) ⇒ Object

Returns the measure duration of the most recent meter duration since the given note offset, or of the start meter if there are no meter changes.



109
110
111
112
113
114
115
116
# File 'lib/musicality/notation/model/score.rb', line 109

def measure_duration note_offset = self.duration
  if meter_changes.any?
    candidates = meter_changes.select {|noff,change| noff <= note_offset }
    candidates.max[1].end_value.measure_duration
  else
    start_meter.measure_duration
  end
end

#meter_change(new_meter, offset: 0) ⇒ Object



75
76
77
# File 'lib/musicality/composition/dsl/score_methods.rb', line 75

def meter_change new_meter, offset: 0
  meter_changes[self.duration + offset] = Change::Immediate.new(new_meter)
end

#tempo_change(new_tempo, transition_dur: 0, offset: 0) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/musicality/composition/dsl/score_methods.rb', line 67

def tempo_change new_tempo, transition_dur: 0, offset: 0
  if transition_dur == 0
    tempo_changes[self.duration + offset] = Change::Immediate.new(new_tempo)
  else
    tempo_changes[self.duration + offset] = Change::Gradual.linear(new_tempo, transition_dur)
  end
end

#to_lilypond(selected_parts = @parts.keys) ⇒ Object

See ScoreEngraver#make_lilypond for details on supported keyword args



6
7
8
# File 'lib/musicality/printing/lilypond/score_engraving.rb', line 6

def to_lilypond selected_parts = @parts.keys
  ScoreEngraver.new(self).make_lilypond(selected_parts)
end

#to_midi_seq(tempo_sample_rate, **kwargs) ⇒ Object



11
12
13
# File 'lib/musicality/performance/midi/score_sequencing.rb', line 11

def to_midi_seq tempo_sample_rate, **kwargs
  to_timed(tempo_sample_rate).to_midi_seq(**kwargs)
end

#to_osc(tempo_sample_rate, base_fpath, **kwargs) ⇒ Object



11
12
13
# File 'lib/musicality/performance/supercollider/score_conducting.rb', line 11

def to_osc tempo_sample_rate, base_fpath, **kwargs
  to_timed(tempo_sample_rate).to_osc(base_fpath, **kwargs)
end

#to_timed(tempo_sample_rate) ⇒ Object

Convert to timed score by converting note-based offsets and durations to time-based. This eliminates the use of meters and tempos.



7
8
9
# File 'lib/musicality/notation/conversion/score_conversion.rb', line 7

def to_timed tempo_sample_rate
  ScoreConverter.new(self, tempo_sample_rate).convert_score
end

#validatablesObject



95
96
97
# File 'lib/musicality/notation/model/score.rb', line 95

def validatables
  super() + [ @start_meter ] + @meter_changes.values.map {|v| v.end_value}
end