<commit_before>module Musicality

class NoteEvent < Event
  attr_reader :note
  def initialize offset, note
    @note = note
    super(offset, note.duration)
  end
end

class Sequencer
  attr_reader :sequence, :note_events, :note_events_future, :note_events_current, :note_events_past
  def initialize sequence
    @sequence = sequence
    
    @note_events = []
    offset = @sequence.offset
    @sequence.notes.each do |note|
      @note_events << NoteEvent.new(offset, note)
      offset += note.duration
    end
    
    @note_events_future = []
    @note_events_current = []
    @note_events_past = []
  end

  def prepare_to_perform start_offset = 0.0
    @note_events_future.clear
    @note_events_current.clear
    @note_events_past.clear
    
    @note_events_future = @note_events.select { |event| event.offset >= start_offset }
    @note_events_past = @note_events.select { |event| event.offset < start_offset }
#    update_notes start_offset
  end

  def update_notes note_counter
    to_start = @note_events_future.select { |event| event.offset <= note_counter }

    to_start.each do |event|
      @note_events_current << event
      @note_events_future.delete event
    end
    
    to_end = @note_events_current.select { |event| note_counter >= (event.offset + event.duration) }

    to_end.each do |event|
      @note_events_past << event
      @note_events_current.delete event
    end
    
    return { :to_start => to_start, :to_end => to_end }
  end
  
  def active?
    !@note_events_current.empty?
  end
end

end<commit_msg>Add comments for Sequence class<commit_after>module Musicality

class NoteEvent < Event
  attr_reader :note
  def initialize offset, note
    @note = note
    super(offset, note.duration)
  end
end

# Assist in the performance of a note sequence. Based on note offset, the 
# sequencer determines if notes are past, current (being played), or future 
# (to be played).
# 
# @author <NAME>
class Sequencer
  attr_reader :sequence, :note_events, :note_events_future, :note_events_current, :note_events_past
  def initialize sequence
    @sequence = sequence
    
    @note_events = []
    offset = @sequence.offset
    @sequence.notes.each do |note|
      @note_events << NoteEvent.new(offset, note)
      offset += note.duration
    end
    
    @note_events_future = []
    @note_events_current = []
    @note_events_past = []
  end

  # Called as part of preparation for performance. Reset note events lists and 
  # for the given note offset, determine which note events are past playing, 
  # and which note events will occur in the future. Rebuild note event lists 
  # accordingly.
  #
  # @param [Float] start_offset The note offset where performance will begin.
  def prepare_to_perform start_offset = 0.0
    @note_events_future.clear
    @note_events_current.clear
    @note_events_past.clear
    
    @note_events_future = @note_events.select { |event| event.offset >= start_offset }
    @note_events_past = @note_events.select { |event| event.offset < start_offset }
#    update_notes start_offset
  end

  # @return [Hash] The notes to either start playing (use key :to_start) or to 
  #                stop playing (use key :to_end).
  def update_notes note_counter
    to_start = @note_events_future.select { |event| event.offset <= note_counter }

    to_start.each do |event|
      @note_events_current << event
      @note_events_future.delete event
    end
    
    to_end = @note_events_current.select { |event| note_counter >= (event.offset + event.duration) }

    to_end.each do |event|
      @note_events_past << event
      @note_events_current.delete event
    end
    
    return { :to_start => to_start, :to_end => to_end }
  end
  
  def active?
    !@note_events_current.empty?
  end
end

end
{'fraction_non_alphanumeric': 0.0865180467091295, 'fraction_numerical': 0.0010615711252653928, 'mean_word_length': 3.292710706150342, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1068914', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1174, 'n_words': 314}