Class: NousPoint

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logic_Controls

#check_bounds, #color_to_hex, #draw_chevron, #hex_to_color, #pos_box, #relative_pos, #round_num_to_grid, #round_to_grid, #set_point_speed, #sync_diff

Constructor Details

#initialize(o, save_id) ⇒ NousPoint

where the point was initially placed, and a unique identifier



509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
# File 'lib/midinous/points.rb', line 509

def initialize(o,save_id) #where the point was initially placed, and a unique identifier
	@dp = [4,8,10,12,14,16,20]
	
	@x = o[0]
	@y = o[1]
	@origin = o
	@bounds = [@x-@dp[5],@y-@dp[5],@x+@dp[5],@y+@dp[5]]
	@color           = GREY #point color defaults to gray++
	@path_color      = CYAN
	@default_color   = GREY
	@note            = 60    #all notes start at middle c (C3), can be a note or a reference
	@velocity        = 100   #       ``       with 100 velocity
	@channel         = 1     #       ``       assigned to midi channel 1 (instrument 1, but we will refer to them as channels, not instruments)
	@duration        = 1     #length of note in grid points (should be considered beats)
	@repeat          = 0     #Number of times the node should repeat before moving on
	@save_id         = save_id
	@play_modes      = ["robin","split","portal","random"]
	@traveler_start  = false
	@playing         = false
	@pathable        = false
	@selected        = false
	@source          = false
	@repeating       = false
	@use_rel         = false
	@mute            = false
	@path_to         = [] #array of references to points that are receiving a path from this point
	@path_to_memory  = [] #memory of @path_to so that it can be reset upon stopping.
	@path_to_rels    = []
	@path_from_rels  = []
	@path_from       = [] #array of references to points that are sending a path to this point
	@path_mode       = "horz"
	@chev_offsets    = [0,0,0,0]
end

Instance Attribute Details

#boundsObject (readonly)

Returns the value of attribute bounds.



507
508
509
# File 'lib/midinous/points.rb', line 507

def bounds
  @bounds
end

#channelObject

Returns the value of attribute channel.



502
503
504
# File 'lib/midinous/points.rb', line 502

def channel
  @channel
end

#colorObject

Returns the value of attribute color.



502
503
504
# File 'lib/midinous/points.rb', line 502

def color
  @color
end

#default_colorObject

Returns the value of attribute default_color.



502
503
504
# File 'lib/midinous/points.rb', line 502

def default_color
  @default_color
end

#durationObject

Returns the value of attribute duration.



502
503
504
# File 'lib/midinous/points.rb', line 502

def duration
  @duration
end

#muteObject

Returns the value of attribute mute.



502
503
504
# File 'lib/midinous/points.rb', line 502

def mute
  @mute
end

#noteObject

Returns the value of attribute note.



502
503
504
# File 'lib/midinous/points.rb', line 502

def note
  @note
end

#originObject

Returns the value of attribute origin.



507
508
509
# File 'lib/midinous/points.rb', line 507

def origin
  @origin
end

#path_fromObject

Returns the value of attribute path_from.



502
503
504
# File 'lib/midinous/points.rb', line 502

def path_from
  @path_from
end

#path_from_relsObject

Returns the value of attribute path_from_rels.



502
503
504
# File 'lib/midinous/points.rb', line 502

def path_from_rels
  @path_from_rels
end

#path_modeObject

Returns the value of attribute path_mode.



502
503
504
# File 'lib/midinous/points.rb', line 502

def path_mode
  @path_mode
end

#path_toObject

Returns the value of attribute path_to.



502
503
504
# File 'lib/midinous/points.rb', line 502

def path_to
  @path_to
end

#path_to_memoryObject

Returns the value of attribute path_to_memory.



502
503
504
# File 'lib/midinous/points.rb', line 502

def path_to_memory
  @path_to_memory
end

#path_to_relsObject

Returns the value of attribute path_to_rels.



502
503
504
# File 'lib/midinous/points.rb', line 502

def path_to_rels
  @path_to_rels
end

#pathableObject (readonly)

Returns the value of attribute pathable.



507
508
509
# File 'lib/midinous/points.rb', line 507

def pathable
  @pathable
end

#play_modesObject

Returns the value of attribute play_modes.



502
503
504
# File 'lib/midinous/points.rb', line 502

def play_modes
  @play_modes
end

#playingObject

Returns the value of attribute playing.



502
503
504
# File 'lib/midinous/points.rb', line 502

def playing
  @playing
end

#repeatObject

Returns the value of attribute repeat.



502
503
504
# File 'lib/midinous/points.rb', line 502

def repeat
  @repeat
end

#repeatingObject

Returns the value of attribute repeating.



502
503
504
# File 'lib/midinous/points.rb', line 502

def repeating
  @repeating
end

#save_idObject

Returns the value of attribute save_id.



502
503
504
# File 'lib/midinous/points.rb', line 502

def save_id
  @save_id
end

#selectedObject

Returns the value of attribute selected.



502
503
504
# File 'lib/midinous/points.rb', line 502

def selected
  @selected
end

#sourceObject

Returns the value of attribute source.



502
503
504
# File 'lib/midinous/points.rb', line 502

def source
  @source
end

#traveler_startObject

Returns the value of attribute traveler_start.



502
503
504
# File 'lib/midinous/points.rb', line 502

def traveler_start
  @traveler_start
end

#use_relObject

Returns the value of attribute use_rel.



502
503
504
# File 'lib/midinous/points.rb', line 502

def use_rel
  @use_rel
end

#velocityObject

Returns the value of attribute velocity.



502
503
504
# File 'lib/midinous/points.rb', line 502

def velocity
  @velocity
end

#xObject

Returns the value of attribute x.



502
503
504
# File 'lib/midinous/points.rb', line 502

def x
  @x
end

#yObject

Returns the value of attribute y.



502
503
504
# File 'lib/midinous/points.rb', line 502

def y
  @y
end

Instance Method Details

#caret_draw(cr) ⇒ Object



754
755
756
757
758
759
760
761
762
# File 'lib/midinous/points.rb', line 754

def caret_draw(cr)
	cr.set_dash([],0)
	@chev_offsets = [0,0,0,0]
	@path_from.each do |s| 
		input_mark_draw(cr,relative_pos(@x-s.x,@y-s.y),s)
		cr.set_source_rgba(s.color[0],s.color[1],s.color[2],1)
		cr.fill
	end
end

#deselectObject

resets the color from elevated ‘selected’ values and sets a flag



635
636
637
638
# File 'lib/midinous/points.rb', line 635

def deselect #resets the color from elevated 'selected' values and sets a flag
	@selected = false
	@color = @default_color
end

#draw(cr) ⇒ Object

point will always be drawn to this specification.



640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
# File 'lib/midinous/points.rb', line 640

def draw(cr) #point will always be drawn to this specification.
	
	cr.set_source_rgba(@color[0],@color[1],@color[2],0.4)
	
	if @traveler_start
		traveler_start_draw(cr)
	else
	  cr.rounded_rectangle(@x-@dp[1],@y-@dp[1],@dp[5],@dp[5],2,2) #slightly smaller rectangle adds 'relief' effect
	end
	cr.fill
	
	cr.set_source_rgba(@color[0],@color[1],@color[2],1)
	case @play_modes[0]
	when "robin"
		if @path_to.length > 1
			cr.move_to(@x-8,@y)
			cr.line_to(@x+6,@y-9)
			cr.set_line_width(2)
			cr.stroke
			cr.move_to(@x-8,@y)
			cr.set_dash([1,4],0)
			cr.line_to(@x+6,@y+9)
			cr.set_line_width(2)
			cr.stroke
			cr.set_dash([],0)
		else
			cr.circle(@x,@y,1)
			cr.fill
		end
	when "split"
		cr.move_to(@x-8,@y)
		cr.line_to(@x+6,@y-9)
		cr.move_to(@x-8,@y)
		cr.line_to(@x+6,@y+9)
		cr.set_line_width(2)
		cr.stroke
	when "portal"
		cr.circle(@x,@y,6)
		cr.set_line_width(2)
		cr.stroke
	when "random"
		cr.rectangle(@x-6,@y-2,8,8)
		cr.rectangle(@x-2,@y-6,8,8)
		cr.set_line_width(2)
		cr.stroke
	end
	
	if @repeat > 0
		if @traveler_start
			cr.move_to(@x+3,@y-@dp[2]-2)
			cr.line_to(@x-2,-6+@y-@dp[2]-2)
			cr.line_to(@x-2,6+@y-@dp[2]-2)
			cr.line_to(@x+3,@y-@dp[2]-2)
			cr.fill
			cr.move_to(@x-3,@y+@dp[2]+2)
			cr.line_to(@x+2,-6+@y+@dp[2]+2)
			cr.line_to(@x+2,6+@y+@dp[2]+2)
			cr.line_to(@x-3,@y+@dp[2]+2)
			cr.fill
		else
			cr.move_to(@x-2,@y-@dp[2])
			cr.line_to(@x-7,-6+@y-@dp[2])
			cr.line_to(@x-7,6+@y-@dp[2])
			cr.line_to(@x-2,@y-@dp[2])
			cr.fill
			cr.move_to(@x+2,@y+@dp[2])
			cr.line_to(@x+7,-6+@y+@dp[2])
			cr.line_to(@x+7,6+@y+@dp[2])
			cr.line_to(@x+2,@y+@dp[2])
			cr.fill
		end
	end
	
	cr.set_dash([2,4],0) if @mute
	if !@selected
		if @traveler_start
			traveler_start_draw(cr)
		else
			cr.rounded_rectangle(@x-@dp[2],@y-@dp[2],@dp[6],@dp[6],2,2)
		end
	end
	if @selected
		cr.set_source_rgba(1,1,1,0.8)
		if @traveler_start			
			traveler_start_draw(cr)
		else
			cr.rounded_rectangle(@x-@dp[2],@y-@dp[2],@dp[6],@dp[6],2,2) #a slightly smaller rectangle adds 'relief' effect
		end
		selection_caret_draw(cr)
	end
	cr.set_line_width(2)
	cr.stroke
	cr.set_dash([],0)
	play_draw(cr) if @playing
	repeat_draw(cr) if @repeating
end

#input_mark_draw(cr, rel_pos, s) ⇒ Object



903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
# File 'lib/midinous/points.rb', line 903

def input_mark_draw(cr,rel_pos,s)
	if    s.path_mode == "horz"
		case rel_pos
		when "n","ne","nw"
			draw_chevron(cr,@chev_offsets[0],"n",self)
			@chev_offsets[0] += 5
		when "s","se","sw"
			draw_chevron(cr,@chev_offsets[1],"s",self)
			@chev_offsets[1] += 5
		when "e"
			draw_chevron(cr,@chev_offsets[2],"e",self)
			@chev_offsets[2] += 5
		when "w"
			draw_chevron(cr,@chev_offsets[3],"w",self)
			@chev_offsets[3] += 5
		end
	elsif s.path_mode == "vert"
		case rel_pos
		when "n"
			draw_chevron(cr,@chev_offsets[0],"n",self)
			@chev_offsets[0] += 5
		when "s"
			draw_chevron(cr,@chev_offsets[1],"s",self)
			@chev_offsets[1] += 5
		when "e","ne","se"
			draw_chevron(cr,@chev_offsets[2],"e",self)
			@chev_offsets[2] += 5
		when "w","nw","sw"
			draw_chevron(cr,@chev_offsets[3],"w",self)
			@chev_offsets[3] += 5
		end
	end
end

#not_pathableObject



572
573
574
# File 'lib/midinous/points.rb', line 572

def not_pathable
	!@pathable
end

#not_selectedObject



569
570
571
# File 'lib/midinous/points.rb', line 569

def not_selected
	!@selected
end

#path_draw(cr) ⇒ Object



737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
# File 'lib/midinous/points.rb', line 737

def path_draw(cr)
	if !@selected
	
		cr.set_source_rgba(@path_color[0],@path_color[1],@path_color[2],0.6)
		@path_to.each {|t| trace_path_to(cr,t)}
		
	elsif @selected
		
		cr.set_source_rgba(LGRN[0],LGRN[1],LGRN[2],0.8)
		@path_to.each   {|t| trace_path_to(cr,t)}
		cr.set_line_cap(1)    #Round
		cr.set_line_join(2)   #Miter
		cr.set_line_width(3)
		cr.stroke
		
	end
end

#path_set(source_chosen) ⇒ Object



583
584
585
586
587
588
589
590
591
592
593
594
# File 'lib/midinous/points.rb', line 583

def path_set(source_chosen)
	@pathable = true
	case source_chosen
		when false       #if source point was not chosen (first point clicked on path screen)
			@source = true #Path source is now chosen on this node
			@color = CYAN
			return true
		when true	       #Path source is already chosen in this operation
			@color = GREEN
	end
	return source_chosen
end

#path_unsetObject



595
596
597
598
599
# File 'lib/midinous/points.rb', line 595

def path_unset
	@pathable = false
	@source = false
	@color = @default_color
end

#play_draw(cr) ⇒ Object

If a note is playing, show a visual indicator



763
764
765
766
767
768
769
770
771
# File 'lib/midinous/points.rb', line 763

def play_draw(cr) #If a note is playing, show a visual indicator
	cr.set_source_rgb(@color[0],@color[1],@color[2])
	if @traveler_start
		traveler_start_draw(cr)
	else
		cr.rounded_rectangle(@x-@dp[2],@y-@dp[2],@dp[6],@dp[6],2,2)
	end
	cr.fill
end

#repeat_draw(cr) ⇒ Object



772
773
774
775
776
# File 'lib/midinous/points.rb', line 772

def repeat_draw(cr)
	cr.set_source_rgb(@color[0],@color[1],@color[2])
	cr.rounded_rectangle(@x-@dp[2]+3,@y-@dp[2]+3,@dp[6]-6,@dp[6]-6,2,2)
	cr.fill
end

#reset_path_toObject



601
602
603
604
605
606
607
608
609
610
# File 'lib/midinous/points.rb', line 601

def reset_path_to
	if @path_to.length != @path_to_memory.length
		@path_to_memory = []
		UI.confirm("path_warning")
	else
		@path_to = []
		@path_to_memory.each {|p| @path_to << p}
		@path_to_memory = []
	end
end

#selectObject

elevate color to denote ‘selected’ and sets a flag



632
633
634
# File 'lib/midinous/points.rb', line 632

def select  #elevate color to denote 'selected' and sets a flag
	@selected = true
end

#selection_caret_draw(cr) ⇒ Object

Shape of a selection caret



789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
# File 'lib/midinous/points.rb', line 789

def selection_caret_draw(cr) #Shape of a selection caret
	cr.move_to(@x-@dp[4],@y-@dp[4])
	cr.line_to(@x-@dp[2],@y-@dp[4])
	cr.move_to(@x-@dp[4],@y-@dp[4])
	cr.line_to(@x-@dp[4],@y-@dp[2])

	cr.move_to(@x+@dp[4],@y-@dp[4])
	cr.line_to(@x+@dp[2],@y-@dp[4])
	cr.move_to(@x+@dp[4],@y-@dp[4])
	cr.line_to(@x+@dp[4],@y-@dp[2])
				
	cr.move_to(@x-@dp[4],@y+@dp[4])
	cr.line_to(@x-@dp[2],@y+@dp[4])
	cr.move_to(@x-@dp[4],@y+@dp[4])
	cr.line_to(@x-@dp[4],@y+@dp[2])
				
	cr.move_to(@x+@dp[4],@y+@dp[4])
	cr.line_to(@x+@dp[2],@y+@dp[4])
	cr.move_to(@x+@dp[4],@y+@dp[4])
	cr.line_to(@x+@dp[4],@y+@dp[2])
end

#set_default_color(c) ⇒ Object



612
613
614
615
# File 'lib/midinous/points.rb', line 612

def set_default_color(c)
	@color = c
	@default_color = c
end

#set_destination(diff) ⇒ Object

sets a new origin for the point based on x,y coordinate differences



626
627
628
629
630
631
# File 'lib/midinous/points.rb', line 626

def set_destination(diff) #sets a new origin for the point based on x,y coordinate differences
	@x += diff[0]
	@y += diff[1]
	@origin = [@x,@y]
	@bounds = [@x-@dp[5],@y-@dp[5],@x+@dp[5],@y+@dp[5]]
end

#set_path_colorObject



616
617
618
619
620
621
622
623
624
625
# File 'lib/midinous/points.rb', line 616

def set_path_color
	case @play_modes[0]
	when "robin","split"
		@path_color = CYAN
	when "portal"
		@path_color = RED
	when "random"
		@path_color = VLET
	end
end

#set_relsObject



543
544
545
546
547
548
# File 'lib/midinous/points.rb', line 543

def set_rels
	@path_to_rels = []
	@path_from_rels = []
	path_to.each {|pt| @path_to_rels << pt.save_id}
	path_from.each {|pf| @path_from_rels << pf.save_id}
end

#trace_path_from(cr, s) ⇒ Object



887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
# File 'lib/midinous/points.rb', line 887

def trace_path_from(cr,s)
	case s.path_mode
	when "horz"
		cr.move_to(s.x,s.y)
		cr.line_to(@x,s.y)
		cr.line_to(@x,@y)
	when "vert"
		cr.move_to(s.x,s.y)
		cr.line_to(s.x,@y)
		cr.line_to(@x,@y)
	when "line"
		cr.move_to(s.x,s.y)
		cr.line_to(@x,@y)
	end
end

#trace_path_to(cr, t) ⇒ Object



810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
# File 'lib/midinous/points.rb', line 810

def trace_path_to(cr,t)
	
	case @play_modes[0]
	when "robin"
		cr.set_dash([5,5],0)
		if @path_to[0] == t
			cr.set_dash([],0)
		end
	when "portal"
		cr.set_dash([1,5],0)
	end
	
	rel_pos = relative_pos(t.x-@x,t.y-@y)
	case rel_pos
	when "n"
		cr.move_to(@x,@y-10)
		cr.line_to(t.x,t.y+10)
	when "s"
		cr.move_to(@x,@y+10)
		cr.line_to(t.x,t.y-10)
	when "e"
		cr.move_to(@x+10,@y)
		cr.line_to(t.x-10,t.y)
	when "w"
		cr.move_to(@x-10,@y)
		cr.line_to(t.x+10,t.y)
	end
	
	case @path_mode
	when "horz"
		case rel_pos
		when "ne"
			cr.move_to(@x+10,@y)
			cr.line_to(t.x,@y)
			cr.line_to(t.x,t.y+10)
		when "nw"
			cr.move_to(@x-10,@y)
			cr.line_to(t.x,@y)
			cr.line_to(t.x,t.y+10)
		when "se"
			cr.move_to(@x+10,@y)
			cr.line_to(t.x,@y)
			cr.line_to(t.x,t.y-10)
		when "sw"
			cr.move_to(@x-10,@y)
			cr.line_to(t.x,@y)
			cr.line_to(t.x,t.y-10)
		end
	when "vert"
		case rel_pos
		when "ne"
			cr.move_to(@x,@y-10)
			cr.line_to(@x,t.y)
			cr.line_to(t.x-10,t.y)
		when "nw"
			cr.move_to(@x,@y-10)
			cr.line_to(@x,t.y)
			cr.line_to(t.x+10,t.y)
		when "se"
			cr.move_to(@x,@y+10)
			cr.line_to(@x,t.y)
			cr.line_to(t.x-10,t.y)
		when "sw"
			cr.move_to(@x,@y+10)
			cr.line_to(@x,t.y)
			cr.line_to(t.x+10,t.y)
		end
	when "line"
		cr.move_to(@x,@y)
		cr.line_to(t.x,t.y)
	end
	cr.set_line_cap(1)    #Round
	cr.set_line_join(2)   #Miter
	cr.set_line_width(3)
	cr.stroke
end

#traveler_start_draw(cr) ⇒ Object

Shape of a traveler start position



778
779
780
781
782
783
784
785
786
787
788
# File 'lib/midinous/points.rb', line 778

def traveler_start_draw(cr) #Shape of a traveler start position
	cr.move_to(@x-@dp[0],@y-@dp[3])
	cr.line_to(@x+@dp[0],@y-@dp[3])
	cr.line_to(@x+@dp[1],@y-@dp[1])
	cr.line_to(@x+@dp[1],@y+@dp[1])
	cr.line_to(@x+@dp[0],@y+@dp[3])
	cr.line_to(@x-@dp[0],@y+@dp[3])
	cr.line_to(@x-@dp[1],@y+@dp[1])
	cr.line_to(@x-@dp[1],@y-@dp[1])
	cr.line_to(@x-@dp[0],@y-@dp[3])
end

#write_props(file) ⇒ Object



550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
# File 'lib/midinous/points.rb', line 550

def write_props(file)
	set_rels
	file.write("#{@save_id}<~>")   
	file.write("#{@origin}<~>")
	file.write("#{@note}<~>")
	file.write("#{@velocity}<~>")
	file.write("#{@channel}<~>")       
	file.write("#{@duration}<~>") 
	file.write("#{color_to_hex(@default_color)}<~>")		
	file.write("#{@repeat}<~>")        
	file.write("#{@play_modes}<~>")    
	file.write("#{@traveler_start}<~>")                       
	file.write("#{@use_rel}<~>")               
	file.write("#{@path_mode}<~>")
	file.write("#{@mute}<~>")
	file.write("#{@path_to_rels}<~>")
	file.write("#{@path_from_rels}")
end