lib/beats/audio_engine.rb
def handle_incoming_overflow(pattern, incoming_overflow, primary_sample_data, overflow_sample_data)
      pattern_track_names = pattern.tracks.keys
      sample_arrays = [primary_sample_data]

      incoming_overflow.each do |incoming_track_name, incoming_sample_data|
        end_sample = incoming_sample_data.length

        if pattern_track_names.member?(incoming_track_name)
          track = pattern.tracks[incoming_track_name]

          if track.trigger_step_lengths.length > 1
            intro_length = (pattern.tracks[incoming_track_name].trigger_step_lengths[0] * step_sample_length).floor
            end_sample = [end_sample, intro_length].min
          end
        end

        if end_sample > primary_sample_data.length
          end_sample = primary_sample_data.length
          overflow_sample_data[incoming_track_name] = incoming_sample_data[(primary_sample_data.length)...(incoming_sample_data.length)]
        end

        sample_arrays << incoming_sample_data[0...end_sample]
      end

      return AudioUtils.composite(sample_arrays, @kit.num_channels), overflow_sample_data
    end
# Applies sound overflow (i.e. long sounds such as cymbal crash which extend past the last step)
# from the previous pattern in the flow to the current pattern. This prevents sounds from being
# cut off when the pattern changes.
#
# It would probably be shorter and conceptually simpler to deal with incoming overflow in
# generate_track_sample_data() instead of this method. (In fact, this method would go away).
# However, doing it this way allows for caching composited pattern sample data, and
# applying incoming overflow to the composite. This allows each pattern to only be composited once,
# regardless of the incoming overflow that each performance of it receives. If incoming overflow
# was handled at the Track level we couldn't do that.
Applies sound overflow
from the previous pattern in the flow to the current pattern. This prevents sounds from being
cut off when the pattern changes.

It would probably be shorter and conceptually simpler to deal with incoming overflow in
generate_track_sample_data() instead of this method. (In fact, this method would go away).
However, doing it this way allows for caching composited pattern sample data, and
applying incoming overflow to the composite. This allows each pattern to only be composited once,
regardless of the incoming overflow that each performance of it receives. If incoming overflow
was handled at the Track level we couldn't do that.
Applies sound overflow from the previous pattern in the flow to the current pattern . This prevents sounds from being cut off when the pattern changes . It would probably be shorter and conceptually simpler to deal with incoming overflow in generate_track_sample_data () instead of this method . ( In fact this method would go away ) . However doing it this way allows for caching composited pattern sample data and applying incoming overflow to the composite . This allows each pattern to only be composited once regardless of the incoming overflow that each performance of it receives . If incoming overflow was handled at the Track level we couldn ' t do that .
def handle_incoming_overflow(pattern, incoming_overflow, primary_sample_data, overflow_sample_data)
      pattern_track_names = pattern.tracks.keys
      sample_arrays = [primary_sample_data]
      incoming_overflow.each do |incoming_track_name, incoming_sample_data|
        end_sample = incoming_sample_data.length
        if pattern_track_names.member?(incoming_track_name)
          track = pattern.tracks[incoming_track_name]
          if track.trigger_step_lengths.length > 1
            intro_length = (pattern.tracks[incoming_track_name].trigger_step_lengths[0] * step_sample_length).floor
            end_sample = [end_sample, intro_length].min
          end
        end
        if end_sample > primary_sample_data.length
          end_sample = primary_sample_data.length
          overflow_sample_data[incoming_track_name] = incoming_sample_data[(primary_sample_data.length)...(incoming_sample_data.length)]
        end
        sample_arrays << incoming_sample_data[0...end_sample]
      end
      return AudioUtils.composite(sample_arrays, @kit.num_channels), overflow_sample_data
    end
def handle_incoming_overflow ( pattern , incoming_overflow , primary_sample_data , overflow_sample_data ) pattern_track_names = pattern . tracks . keys sample_arrays = [ primary_sample_data ] incoming_overflow . each do | incoming_track_name , incoming_sample_data | end_sample = incoming_sample_data . length if pattern_track_names . member? ( incoming_track_name ) track = pattern . tracks [ incoming_track_name ] if track . trigger_step_lengths . length > 1 intro_length = ( pattern . tracks [ incoming_track_name ] . trigger_step_lengths [ 0 ] * step_sample_length ) . floor end_sample = [ end_sample , intro_length ] . min end end if end_sample > primary_sample_data . length end_sample = primary_sample_data . length overflow_sample_data [ incoming_track_name ] = incoming_sample_data [ ( primary_sample_data . length ) ... ( incoming_sample_data . length ) ] end sample_arrays << incoming_sample_data [ 0 ... end_sample ] end return AudioUtils . composite ( sample_arrays , @kit . num_channels ) , overflow_sample_data end
Applies sound overflow (i.e.
Applies sound overflow ( i . e .
pattern
incoming_overflow
primary_sample_data
overflow_sample_data