Class: LiveAudioTrack

Inherits:
Object
  • Object
show all
Defined in:
lib/live_set/live_set_audio_track.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(audio_track) ⇒ LiveAudioTrack

Returns a new instance of LiveAudioTrack.

Parameters:

  • audio_track

    is an <AudioTrack/> element from an Ableton Live .als file as parsed by Nokogiri



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/live_set/live_set_audio_track.rb', line 5

def initialize(audio_track)
  @audio_track = audio_track
  @id = @audio_track['Id']

  @frozen = @audio_track.Freeze['Value'].to_bool

  @clip_slots = @audio_track.DeviceChain.MainSequencer.ClipSlotList
  @audio_clips = @clip_slots.ClipSlot.map do |clip_slot|
    clip_slot_id = clip_slot['Id']
    need_refreeze = clip_slot.NeedRefreeze['Value'].to_bool
    inner_clip_slot = clip_slot.ClipSlot
    LiveAudioClip.new clip_slot_id, need_refreeze, inner_clip_slot if
      inner_clip_slot.respond_to?(:Value) && !inner_clip_slot.Value.children.empty?
  end
  @audio_clips.compact!
  @track_size = @audio_clips.sum(&:file_size) || 0
end

Instance Attribute Details

#audio_clipsObject (readonly)

Returns the value of attribute audio_clips.



2
3
4
# File 'lib/live_set/live_set_audio_track.rb', line 2

def audio_clips
  @audio_clips
end

#clip_slotsObject (readonly)

Returns the value of attribute clip_slots.



2
3
4
# File 'lib/live_set/live_set_audio_track.rb', line 2

def clip_slots
  @clip_slots
end

#frozenObject (readonly)

Returns the value of attribute frozen.



2
3
4
# File 'lib/live_set/live_set_audio_track.rb', line 2

def frozen
  @frozen
end

#idObject (readonly)

Returns the value of attribute id.



2
3
4
# File 'lib/live_set/live_set_audio_track.rb', line 2

def id
  @id
end

#track_sizeObject (readonly)

Returns the value of attribute track_size.



2
3
4
# File 'lib/live_set/live_set_audio_track.rb', line 2

def track_size
  @track_size
end

Instance Method Details

#clips_collected?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/live_set/live_set_audio_track.rb', line 23

def clips_collected?
  @audio_clips.all?(&:collected?)
end

#show_clipsObject



34
35
36
37
38
39
# File 'lib/live_set/live_set_audio_track.rb', line 34

def show_clips
  return '' if @track_size.zero?

  result = @audio_clips.map(&:show_clip)
  result.columnize '  '
end

#show_track(all_frozen) ⇒ Object



27
28
29
30
31
32
# File 'lib/live_set/live_set_audio_track.rb', line 27

def show_track(all_frozen)
  name = @audio_track.Name.EffectiveName['Value']
  frozen = @audio_track.frozen? ? ' frozen'.green : ' **not frozen**'.red unless all_frozen || @audio_clips.empty?
  size = ", totaling #{human_file_size @track_size}" unless @audio_clips.empty?
  "Track '#{name}'#{frozen} (#{@audio_clips.length} clips#{size})\n" + show_clips
end