Class: Traveler

Inherits:
Object
  • Object
show all
Defined in:
lib/midinous/points.rb

Overview

A traveler handles the source note playing and creates another traveler if the destination is reached.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(srce, dest, lpn) ⇒ Traveler

Traveler should play note when reaches destination. Should not need to create another traveler if it’s a dead end.



899
900
901
902
903
904
905
906
907
908
909
910
911
912
# File 'lib/midinous/points.rb', line 899

def initialize(srce,dest,lpn) #Traveler should play note when reaches destination. Should not need to create another traveler if it's a dead end.
	@srce        = srce
	@dest        = dest
	@srce_origin = srce.origin
	@dest_origin = dest.origin
	@repeat      = dest.repeat
	@travel_c    = 0
	@iteration   = 0
	@last_played_note = lpn
	@played_note = nil
	@distance    = ((@dest_origin[0] - @srce_origin[0]).abs + (@dest_origin[1] - @srce_origin[1]).abs)/CC.grid_spacing
	@reached     = false
	@remove      = false
end

Instance Attribute Details

#destObject (readonly)

Returns the value of attribute dest.



897
898
899
# File 'lib/midinous/points.rb', line 897

def dest
  @dest
end

#dest_originObject (readonly)

Returns the value of attribute dest_origin.



897
898
899
# File 'lib/midinous/points.rb', line 897

def dest_origin
  @dest_origin
end

#last_played_noteObject (readonly)

Returns the value of attribute last_played_note.



897
898
899
# File 'lib/midinous/points.rb', line 897

def last_played_note
  @last_played_note
end

#played_noteObject (readonly)

Returns the value of attribute played_note.



897
898
899
# File 'lib/midinous/points.rb', line 897

def played_note
  @played_note
end

#reachedObject

Returns the value of attribute reached.



898
899
900
# File 'lib/midinous/points.rb', line 898

def reached
  @reached
end

#removeObject (readonly)

Returns the value of attribute remove.



897
898
899
# File 'lib/midinous/points.rb', line 897

def remove
  @remove
end

Instance Method Details

#play_check(srce_rel, dest_rel) ⇒ Object



927
928
929
930
931
932
933
934
935
936
937
938
# File 'lib/midinous/points.rb', line 927

def play_check(srce_rel,dest_rel)
	if !dest_rel
		@played_note = @dest.note
		play_note
	elsif  srce_rel && dest_rel
		@played_note = @last_played_note
		play_relative
	elsif !srce_rel && dest_rel
		@played_note = @srce.note.to_i
		play_relative
	end
end

#play_noteObject



939
940
941
942
943
# File 'lib/midinous/points.rb', line 939

def play_note
	queued_notes = []
	CC.queued_note_plays.each {|q| queued_notes << [q.note,q.chan]}		
	CC.queued_note_plays << NoteSender.new(@played_note,@dest.channel,@dest.velocity) unless queued_notes.find {|f| @played_note == f[0] && @dest.channel == f[1]}
end

#play_relativeObject



944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
# File 'lib/midinous/points.rb', line 944

def play_relative
	#search the current scales variable and round to nearest note.
	rel = @dest.note.to_i
	pn  = @played_note
	if @dest.note.to_s.include?("+")
		(pn..127).each do |s|
			rel -= 1 if CC.scale_posns[s] == true && s != pn
			if rel == 0
				pn = s 
				break
			end
		end
	elsif @dest.note.to_s.include?("-")
		(0..pn).reverse_each do |s|
			rel += 1 if CC.scale_posns[s] == true && s != pn
			if rel == 0
				pn = s 
				break
			end
		end
	end
	@played_note = pn
	play_note
end

#queue_removalObject



969
970
971
972
973
# File 'lib/midinous/points.rb', line 969

def queue_removal
	CC.queued_note_stops << NoteSender.new(@played_note,@dest.channel,0)

	@remove = true
end

#travelObject



914
915
916
917
918
919
920
921
922
923
924
925
# File 'lib/midinous/points.rb', line 914

def travel
	@travel_c += 1
	if @travel_c == @distance
		@dest.playing = true
		@reached = true
		play_check(@srce.use_rel,@dest.use_rel)
	elsif @travel_c == (@distance + @dest.duration) 
		@dest.playing = false
		CC.repeaters << Repeater.new(@dest,@repeat,@played_note) if @repeat > 0
		queue_removal
	end
end