Class: AudioStream::AudioInputStepEditor

Inherits:
Object
  • Object
show all
Includes:
AudioInput
Defined in:
lib/audio_stream/audio_input_step_editor.rb

Instance Method Summary collapse

Constructor Details

#initialize(synth, step_editor) ⇒ AudioInputStepEditor

Returns a new instance of AudioInputStepEditor.



5
6
7
8
9
10
11
12
# File 'lib/audio_stream/audio_input_step_editor.rb', line 5

def initialize(synth, step_editor)
  super()

  @synth = synth
  @step_editor = step_editor

  @soundinfo = synth.soundinfo
end

Instance Method Details

#connectObject



14
15
16
# File 'lib/audio_stream/audio_input_step_editor.rb', line 14

def connect
  self
end

#connected?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/audio_stream/audio_input_step_editor.rb', line 22

def connected?
  true
end

#disconnectObject



18
19
20
# File 'lib/audio_stream/audio_input_step_editor.rb', line 18

def disconnect
  self
end

#each(&block) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/audio_stream/audio_input_step_editor.rb', line 26

def each(&block)
  Enumerator.new do |y|
    events = Hash.new {|h, k| h[k]=[]}

    fps = @soundinfo.samplerate.to_f / @soundinfo.window_size
    @step_editor.events.each {|event|
      pos = event[0]
      events[(pos * fps).to_i] << event
    }

    catch :break do
      Range.new(0, nil).each {|i|
        if events.has_key?(i)
          events[i].sort{|a,b| a[0]<=>b[0]}.each {|event|
            type = event[1]

            case type
            when :note_on
              @synth.note_on(event[2], velocity: event[3])
            when :note_off
              @synth.note_off(event[2])
            when :pitch_bend
              @synth.pitch_bend = event[2]
            when :complete
              throw :break
            end
          }
        end

        buf = @synth.next
        y << buf
      }
    end
  end.each(&block)
end