Class: Traveler
- Inherits:
-
Object
- Object
- Traveler
- 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
-
#dest ⇒ Object
readonly
Returns the value of attribute dest.
-
#dest_origin ⇒ Object
readonly
Returns the value of attribute dest_origin.
-
#last_played_note ⇒ Object
readonly
Returns the value of attribute last_played_note.
-
#played_note ⇒ Object
readonly
Returns the value of attribute played_note.
-
#reached ⇒ Object
Returns the value of attribute reached.
-
#remove ⇒ Object
readonly
Returns the value of attribute remove.
Instance Method Summary collapse
-
#initialize(srce, dest, lpn) ⇒ Traveler
constructor
Traveler should play note when reaches destination.
- #play_check(srce_rel, dest_rel) ⇒ Object
- #play_note ⇒ Object
- #play_relative ⇒ Object
- #queue_removal ⇒ Object
- #travel ⇒ Object
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
#dest ⇒ Object (readonly)
Returns the value of attribute dest.
897 898 899 |
# File 'lib/midinous/points.rb', line 897 def dest @dest end |
#dest_origin ⇒ Object (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_note ⇒ Object (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_note ⇒ Object (readonly)
Returns the value of attribute played_note.
897 898 899 |
# File 'lib/midinous/points.rb', line 897 def played_note @played_note end |
#reached ⇒ Object
Returns the value of attribute reached.
898 899 900 |
# File 'lib/midinous/points.rb', line 898 def reached @reached end |
#remove ⇒ Object (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_note ⇒ Object
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_relative ⇒ Object
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_removal ⇒ Object
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 |
#travel ⇒ Object
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. = true @reached = true play_check(@srce.use_rel,@dest.use_rel) elsif @travel_c == (@distance + @dest.duration) @dest. = false CC.repeaters << Repeater.new(@dest,@repeat,@played_note) if @repeat > 0 queue_removal end end |