Class: MusaLCEServer::Live::Tracks Private

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/live/tracks.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Collection of tracks for Ableton Live.

Manages track registration and lookup, automatically creating and updating tracks based on OSC messages from the MIDI Remote Script.

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initialize(midi_devices, logger:) ⇒ Tracks

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new tracks collection.

Parameters:

  • midi_devices (MIDIDevices)

    the MIDI devices manager

  • logger (Logger)

    the logger

Since:

  • 0.1.0



110
111
112
113
114
# File 'lib/live/tracks.rb', line 110

def initialize(midi_devices, logger:)
  @midi_devices = midi_devices
  @logger = logger
  @tracks = {}
end

Instance Method Details

#[](id) ⇒ Track?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Retrieves a track by ID.

Parameters:

  • id (Integer)

    the track ID

Returns:

  • (Track, nil)

    the track or nil if not found

Since:

  • 0.1.0



187
188
189
# File 'lib/live/tracks.rb', line 187

def [](id)
  @tracks[id]
end

#each {|Track| ... } ⇒ Enumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Iterates over all tracks.

Yields:

Returns:

  • (Enumerator)

    if no block given

Since:

  • 0.1.0



175
176
177
178
179
180
181
# File 'lib/live/tracks.rb', line 175

def each(&block)
  if block_given?
    @tracks.values.each(&block)
  else
    @tracks.values.each
  end
end

#find_by_name(name) ⇒ Array<Track>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO:

Adapt to Bitwig semantics where track names are unique

Finds all tracks with the given name.

Parameters:

  • name (String)

    the track name

Returns:

  • (Array<Track>)

    matching tracks

Since:

  • 0.1.0



197
198
199
# File 'lib/live/tracks.rb', line 197

def find_by_name(name)
  @tracks.values.select { |_| _.name == name }
end

#grant_registry(id, name = nil, has_midi_input = nil, has_midi_output = nil, has_audio_input = nil, has_audio_output = nil, current_input_routing = nil, current_input_sub_routing = nil, current_output_routing = nil, current_output_sub_routing = nil) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Registers or updates a track with the provided data.

Parameters:

  • id (Integer)

    the track ID

  • name (String, nil) (defaults to: nil)

    the track name

  • has_midi_input (Integer, nil) (defaults to: nil)

    1 if track has MIDI input

  • has_midi_output (Integer, nil) (defaults to: nil)

    1 if track has MIDI output

  • has_audio_input (Integer, nil) (defaults to: nil)

    1 if track has audio input

  • has_audio_output (Integer, nil) (defaults to: nil)

    1 if track has audio output

  • current_input_routing (String, nil) (defaults to: nil)

    input routing device name

  • current_input_sub_routing (String, nil) (defaults to: nil)

    input sub-routing (channel)

  • current_output_routing (String, nil) (defaults to: nil)

    output routing device name

  • current_output_sub_routing (String, nil) (defaults to: nil)

    output sub-routing

Since:

  • 0.1.0



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/live/tracks.rb', line 147

def grant_registry(id, name = nil,
                   has_midi_input = nil, has_midi_output = nil,
                   has_audio_input = nil, has_audio_output = nil,
                   current_input_routing = nil, current_input_sub_routing = nil,
                   current_output_routing = nil, current_output_sub_routing = nil)

  track = @tracks[id]

  unless track
    track = Track.new(id, @midi_devices, logger: @logger)
    @tracks[id] = track
  end

  track._update_name(name) if name
  track._update_has_midi_input(has_midi_input) if has_midi_input
  track._update_has_midi_output(has_midi_output) if has_midi_output
  track._update_has_audio_input(has_audio_input) if has_audio_input
  track._update_has_audio_output(has_audio_output) if has_audio_output
  track._update_current_input_routing(parse_device_name(current_input_routing)) if current_input_routing
  track._update_current_input_sub_routing(current_input_sub_routing) if current_input_sub_routing
  track._update_current_output_routing(parse_device_name(current_output_routing)) if current_output_routing
  track._update_current_output_sub_routing(current_output_sub_routing) if current_output_sub_routing
end

#grant_registry_collection(tracks_data) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Processes a batch of track data, creating, updating, and deleting tracks.

Parameters:

  • tracks_data (Array<Array>)

    array of track data arrays

Since:

  • 0.1.0



120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/live/tracks.rb', line 120

def grant_registry_collection(tracks_data)
  tracks_to_delete = Set[*@tracks.keys]

  tracks_data.each do |track_data|
    grant_registry(*track_data)
    tracks_to_delete.delete track_data[0]
  end

  tracks_to_delete.each do |id|
    @tracks.delete(id)
    @logger.info "deleted track #{id}"
  end
end