Class: Musicality::SuperCollider::Conductor

Inherits:
Object
  • Object
show all
Defined in:
lib/musicality/performance/supercollider/conductor.rb

Instance Method Summary collapse

Constructor Details

#initialize(score) ⇒ Conductor

Returns a new instance of Conductor.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/musicality/performance/supercollider/conductor.rb', line 5

def initialize score
  unless score.is_a?(Score::Timed)
    raise ArgumentError, "The given score is not a Score::Timed. \
    Convert it first using ScoreConverter."
  end

  parts = score.collated? ? score.parts : ScoreCollator.new(score).collate_parts
  @performers = Hash[ parts.map do |name, part|
    [name, Performer.new(part)]
  end]
end

Instance Method Details

#bundles(selected_parts = @performers.keys, lead_time) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/musicality/performance/supercollider/conductor.rb', line 24

def bundles selected_parts = @performers.keys, lead_time
  Node.reset_id_counter

  default_group = Group.default(nil)
  aux_audio_bus = 16
  volume_control_bus = 0
  bundle_kwargs = {
    :parent_group => default_group,
    :aux_audio_bus => aux_audio_bus,
    :volume_control_bus => volume_control_bus,
    :lead_time => lead_time
  }

  all_bundles = [ default_group.bundle_queue(0.0) ]
  selected_parts.each do |name|
    bundles = @performers[name].bundles(**bundle_kwargs)
    bundle_kwargs[:aux_audio_bus] += 2
    bundle_kwargs[:volume_control_bus] += 1
    all_bundles.concat bundles
  end
  all_bundles = all_bundles.sort_by {|b| b.time }
  default_group.free_all
  all_bundles.push(default_group.bundle_queue(lead_time+all_bundles.last.time))

  coalesced_bundles = []
  all_bundles.each do |bundle|
    if coalesced_bundles.any? && coalesced_bundles.last.time == bundle.time
      coalesced_bundles.last.messages.concat bundle.messages
    else
      coalesced_bundles.push bundle
    end
  end

  return coalesced_bundles
end

#perform(base_fpath, selected_parts: @performers.keys, verbose: false, lead_time: 0.1, keep_code: false) ⇒ Object



17
18
19
20
21
22
# File 'lib/musicality/performance/supercollider/conductor.rb', line 17

def perform base_fpath, selected_parts: @performers.keys, verbose: false, lead_time: 0.1, keep_code: false
  bundles = bundles(selected_parts, lead_time)
  fpath = write_sc_code bundles, base_fpath
  exec_sc_code fpath, bundles.last.time, verbose
  File.delete(fpath) unless keep_code
end