@@ -2,27 +2,33 @@ use crate::{
22 midi,
33 widget:: { ByTitle , MidiController01Udp , Widget } ,
44} ;
5- use caw_core:: { Sig , SigShared } ;
5+ use caw_core:: { IsPositive , Sig , SigShared } ;
66use caw_midi:: MidiMessagesT ;
77use lazy_static:: lazy_static;
88
9+ pub type KnobWithSpace = (
10+ Sig < SigShared < MidiController01Udp > > ,
11+ Sig < SigShared < IsPositive < MidiController01Udp > > > ,
12+ ) ;
13+
914lazy_static ! {
1015 // Used to prevent multiple windows from opening at the same time with the same name. Note that
1116 // when using with evcxr this seems to get cleared when a cell is recomputed, but this is still
1217 // valuable in the context of stereo signals, where a function is evaluated once for the left
1318 // channel and once for the right channel. In such a case, this prevents each knob openned by
1419 // that function from being openned twice.
15- static ref BY_TITLE : ByTitle <Sig < SigShared < MidiController01Udp >> > = Default :: default ( ) ;
20+ static ref BY_TITLE : ByTitle <KnobWithSpace > = Default :: default ( ) ;
1621}
1722
18- fn new_knob (
23+ fn new_knob_with_space (
1924 title : String ,
2025 initial_value_01 : f32 ,
2126 sensitivity : f32 ,
22- ) -> Sig < SigShared < MidiController01Udp > > {
27+ ) -> KnobWithSpace {
2328 BY_TITLE . get_or_insert ( title. as_str ( ) , || {
2429 let channel = midi:: alloc_channel ( ) ;
2530 let controller = midi:: alloc_controller ( channel) ;
31+ let space_controller = midi:: alloc_controller ( channel) ;
2632 let widget = Widget :: new (
2733 title. clone ( ) ,
2834 channel,
@@ -31,18 +37,31 @@ fn new_knob(
3137 format!( "--controller={}" , controller) ,
3238 format!( "--initial-value={}" , initial_value_01) ,
3339 format!( "--sensitivity={}" , sensitivity) ,
40+ format!( "--space-controller={}" , space_controller) ,
3441 ] ,
3542 )
3643 . unwrap ( ) ;
37- widget
38- . channel ( )
39- . controllers ( )
44+ let controllers = widget. channel ( ) . controllers ( ) ;
45+ let value = controllers
4046 . get_with_initial_value_01 ( controller. into ( ) , initial_value_01)
41- . shared ( )
47+ . shared ( ) ;
48+ let space = controllers
49+ . get_with_initial_value_01 ( space_controller. into ( ) , 0.0 )
50+ . is_positive ( )
51+ . shared ( ) ;
52+ ( value, space)
4253 } )
4354}
4455
45- mod knob_builder {
56+ fn new_knob (
57+ title : String ,
58+ initial_value_01 : f32 ,
59+ sensitivity : f32 ,
60+ ) -> Sig < SigShared < MidiController01Udp > > {
61+ new_knob_with_space ( title, initial_value_01, sensitivity) . 0
62+ }
63+
64+ mod builder {
4665 use super :: * ;
4766 use caw_builder_proc_macros:: builder;
4867 use caw_core:: { Sig , SigShared } ;
@@ -53,7 +72,7 @@ mod knob_builder {
5372 #[ generic_setter_type_name = "X" ]
5473 #[ build_fn = "new_knob" ]
5574 #[ build_ty = "Sig<SigShared<MidiController01Udp>>" ]
56- pub struct Props {
75+ pub struct KnobProps {
5776 title: String ,
5877 #[ default = 0.5 ]
5978 initial_value_01: f32 ,
@@ -62,9 +81,28 @@ mod knob_builder {
6281 }
6382 }
6483
65- pub fn knob ( title : impl Into < String > ) -> Props {
84+ pub fn knob ( title : impl Into < String > ) -> KnobProps {
6685 knob_ ( title. into ( ) )
6786 }
87+
88+ builder ! {
89+ #[ constructor = "knob_with_space_" ]
90+ #[ constructor_doc = "A visual knob in a new window" ]
91+ #[ generic_setter_type_name = "X" ]
92+ #[ build_fn = "new_knob_with_space" ]
93+ #[ build_ty = "KnobWithSpace" ]
94+ pub struct KnobWithSpaceProps {
95+ title: String ,
96+ #[ default = 0.5 ]
97+ initial_value_01: f32 ,
98+ #[ default = 0.2 ]
99+ sensitivity: f32 ,
100+ }
101+ }
102+
103+ pub fn knob_with_space ( title : impl Into < String > ) -> KnobWithSpaceProps {
104+ knob_with_space_ ( title. into ( ) )
105+ }
68106}
69107
70- pub use knob_builder :: knob;
108+ pub use builder :: { knob, knob_with_space } ;
0 commit comments