1
1
use crate :: util;
2
- use nih_plug:: prelude:: { AtomicF32 , Editor , Param } ;
2
+ use nih_plug:: prelude:: { AtomicF32 , Editor } ;
3
3
use nih_plug_vizia:: vizia:: prelude:: * ;
4
4
use nih_plug_vizia:: vizia:: vg;
5
5
use nih_plug_vizia:: widgets:: * ;
@@ -12,6 +12,8 @@ use crate::Del2Params;
12
12
use crate :: DelayData ;
13
13
use crate :: DelayDataOutput ;
14
14
use crate :: LastPlayedNotes ;
15
+ use crate :: LEARNING ;
16
+ use crate :: NO_LEARNED_NOTE ;
15
17
16
18
#[ derive( Lens , Clone ) ]
17
19
pub ( crate ) struct Data {
@@ -109,16 +111,6 @@ pub fn create(editor_data: Data, editor_state: Arc<ViziaState>) -> Option<Box<dy
109
111
Label :: new ( cx, "release" ) . class ( "slider-label" ) ;
110
112
ParamSlider :: new ( cx, Data :: params, |params| & params. global . release_ms )
111
113
. class ( "widget" ) ;
112
- Label :: new (
113
- cx,
114
- Data :: params. map ( |params| {
115
- params. global . release_ms . normalized_value_to_string (
116
- params. global . release_ms . modulated_normalized_value ( ) ,
117
- true ,
118
- )
119
- } ) ,
120
- )
121
- . class ( "slider-label" ) ;
122
114
} )
123
115
. class ( "row" ) ;
124
116
} ) // TODO: make into a class
@@ -496,12 +488,6 @@ impl DelayGraph {
496
488
}
497
489
// TODO: .overflow(Overflow::Visible);
498
490
499
- fn u8_note_to_name ( note_nr : u8 ) -> String {
500
- let note_name = util:: NOTES [ ( note_nr % 12 ) as usize ] ;
501
- let octave = ( note_nr / 12 ) - 1 ;
502
- format ! ( "{note_name}{octave}" )
503
- }
504
-
505
491
fn draw_bounding_outline (
506
492
& self ,
507
493
canvas : & mut Canvas ,
@@ -548,7 +534,6 @@ pub struct ActionTrigger {
548
534
impl ActionTrigger {
549
535
pub fn new < IsLearningL , LearningIndexL , LearnedNotesL , LastPlayedNotesL > (
550
536
cx : & mut Context ,
551
-
552
537
is_learning : IsLearningL ,
553
538
learning_index : LearningIndexL ,
554
539
own_index : usize ,
@@ -568,31 +553,50 @@ impl ActionTrigger {
568
553
learned_notes : learned_notes. get ( cx) ,
569
554
last_played_notes : last_played_notes. get ( cx) ,
570
555
}
571
- . build ( cx, |_cx| {
572
- // Label::new(cx, "XXX").class("global-title");
573
- // put other widgets here
556
+ . build ( cx, move |cx| {
557
+ Label :: new (
558
+ cx,
559
+ learned_notes. clone ( ) . map ( move |notes| {
560
+ let note_nr = notes. load ( own_index) ;
561
+ ActionTrigger :: get_note_name ( note_nr)
562
+ } ) ,
563
+ )
564
+ . class ( "action-label" ) ;
574
565
} )
575
566
}
576
567
577
568
pub fn start_learning ( & self ) {
578
569
self . is_learning . store ( true , Ordering :: SeqCst ) ;
579
- self . learning_index . store ( self . own_index , Ordering :: SeqCst ) ;
570
+ let index = self . own_index ;
571
+ self . learned_notes . store ( index, LEARNING ) ;
572
+ self . learning_index . store ( index, Ordering :: SeqCst ) ;
580
573
}
581
574
pub fn stop_learning ( & self ) {
582
575
self . is_learning . store ( false , Ordering :: SeqCst ) ;
583
576
}
584
577
585
578
// Checks if learning is active for this trigger
586
579
pub fn is_learning ( & self ) -> bool {
587
- self . is_learning . load ( Ordering :: SeqCst )
588
- && self . learning_index . load ( Ordering :: SeqCst ) == self . own_index
580
+ self . learned_notes . load ( self . own_index ) == LEARNING
589
581
}
590
582
591
583
pub fn is_playing ( & self ) -> bool {
592
584
self . last_played_notes
593
585
. is_playing ( self . learned_notes . load ( self . own_index ) )
594
586
}
595
587
588
+ fn get_note_name ( note_nr : u8 ) -> String {
589
+ if note_nr == LEARNING {
590
+ "learning" . to_string ( )
591
+ } else if note_nr == NO_LEARNED_NOTE {
592
+ "click to learn" . to_string ( )
593
+ } else {
594
+ let note_name = util:: NOTES [ ( note_nr % 12 ) as usize ] ;
595
+ let octave = ( note_nr / 12 ) - 1 ;
596
+ format ! ( "{note_name}{octave}" )
597
+ }
598
+ }
599
+
596
600
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
597
601
// for drawing
598
602
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
0 commit comments