Sha256: 2a62b82c97af4f4b9ccb347019f418449dd7601069dd4f22f421057a896ab3c3

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 KB

Contents

module Music
module Transcription

class Change
  attr_reader :value, :duration
  
  def initialize value, duration
    @value = value
    @duration = duration
  end
  
  def ==(other)
    self.class == other.class &&
    self.value == other.value &&
    self.duration == other.duration
  end

  class Immediate < Change
    def initialize value
      super(value,0)
    end
    
    def clone
      Immediate.new(@value)
    end
    
    def resize newdur
      self.clone
    end
  end
  
  class Gradual < Change
    def initialize value, transition_dur
      if transition_dur <= 0
        raise NonPositiveError, "transition duration #{transition_dur} must be positive"
      end
      super(value, transition_dur)
    end
    
    def clone
      Gradual.new(@value,@duration)
    end
    
    def resize newdur
      Gradual.new(@value,newdur)
    end
  end
  
  class Partial < Change
    attr_reader :total_duration, :elapsed, :stop
    
    def initialize value, total_dur, elapsed, stop
      if elapsed < 0
        raise NegativeError, "elapsed (#{elapsed}) is < 0"
      end
      
      if stop <= 0
        raise NonPositiveError, "stop (#{stop}) is < 0"
      end

      if stop > total_dur
        raise ArgumentError, "stop (#{stop}) is > total duration (#{total_dur})"
      end
      
      if stop <= elapsed
        raise ArgumentError, "stop (#{stop}) is <= elapsed (#{elapsed})"
      end

      @total_duration = total_dur
      @elapsed = elapsed
      @stop = stop
      super(value,stop - elapsed)
    end
    
    def ==(other)
      super() &&
      @elapsed == other.elapsed &&
      @stop == other.stop
    end
  end
end

end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
music-transcription-0.21.0 lib/music-transcription/model/change.rb
music-transcription-0.20.0 lib/music-transcription/model/change.rb