Method: GameListener#move
- Defined in:
- lib/bangkok/gamelistener.rb
#move(piece, from, to) ⇒ Object
Move piece from one space to another. Generate two notes and sets CC_PORTAMENTO_TIME so there is a glide from the first note to the second. Also output multiple volume and pan values, moving smoothly from the original to the new value.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/bangkok/gamelistener.rb', line 114 def move(piece, from, to) raise "from #{from} may not be off the board" unless from.on_board? # Do nothing if the piece moves off the board, because either capture() # or pawn_to_queen() will be called. return unless to.on_board? track = track_of(piece) channel = channel_of(piece) dist = from.distance_to(to) total_delta = @seq.length_to_delta(dist) # quarter note per space generate_notes(track, channel, total_delta, piece, from, to) generate_portamento(track, channel, total_delta) steps = interpolate(16, 64, 0, @max_delta, total_delta).to_i delta = (total_delta / steps).to_i start = @time_from_start steps.times { | step | val = rank_to_volume(interpolate(from.rank, to.rank, 0, steps-1, step)) generate_volume(track, channel, start, val) val = file_to_pan(interpolate(from.file, to.file, 0, steps-1, step)) generate_pan(track, channel, start, val) start += delta } @time_from_start += total_delta end |