11use crate :: {
22 midi,
33 server:: MidiChannelUdp ,
4- widget:: { ByTitle , Widget } ,
4+ widget:: { ByTitle , MidiControllerBoolUdp , Widget } ,
55} ;
66use caw_core:: { Sig , SigShared , sig_shared} ;
77use caw_keyboard:: Note ;
88use caw_midi:: { MidiKeyPress , MidiMessagesT } ;
99use lazy_static:: lazy_static;
1010
11- pub type Button = MidiKeyPress < MidiChannelUdp > ;
11+ pub type ButtonWithSpace = (
12+ Sig < SigShared < MidiKeyPress < MidiChannelUdp > > > ,
13+ Sig < SigShared < MidiControllerBoolUdp > > ,
14+ ) ;
1215
1316lazy_static ! {
14- static ref BY_TITLE : ByTitle <Sig < SigShared < Button >> > = Default :: default ( ) ;
17+ static ref BY_TITLE : ByTitle <ButtonWithSpace > = Default :: default ( ) ;
1518}
1619
17- fn new_button ( title : String ) -> Sig < SigShared < Button > > {
20+ fn new_button_with_space ( title : String ) -> ButtonWithSpace {
1821 let ( channel, key) = midi:: alloc_key ( ) ;
22+ let ( space_channel, space_controller) = midi:: alloc_controller ( ) ;
1923 let note = Note :: from_midi_index ( key) ;
2024 BY_TITLE . get_or_insert ( title. as_str ( ) , || {
2125 let widget = Widget :: new (
2226 title. clone ( ) ,
2327 channel,
2428 "button" ,
25- vec ! [ format!( "--note={}" , note) ] ,
29+ vec ! [
30+ format!( "--note={}" , note) ,
31+ format!( "--space-channel={}" , space_channel) ,
32+ format!( "--space-controller={}" , space_controller) ,
33+ ] ,
2634 )
2735 . unwrap ( ) ;
28- // The choice of note here is arbitrary.
29- sig_shared ( widget. channel ( ) . key_press ( note) )
36+ let controllers = widget. channel ( ) . controllers ( ) ;
37+ let value = sig_shared ( widget. channel ( ) . key_press ( note) ) ;
38+ let space = controllers. get_bool ( space_controller. into ( ) ) . shared ( ) ;
39+ ( value, space)
3040 } )
3141}
3242
43+ fn new_button ( title : String ) -> Sig < SigShared < MidiKeyPress < MidiChannelUdp > > > {
44+ new_button_with_space ( title) . 0
45+ }
46+
3347mod builder {
3448 use super :: * ;
3549 use caw_builder_proc_macros:: builder;
@@ -40,7 +54,7 @@ mod builder {
4054 #[ constructor_doc = "A visual button in a new window" ]
4155 #[ generic_setter_type_name = "X" ]
4256 #[ build_fn = "new_button" ]
43- #[ build_ty = "Sig<SigShared<Button >>" ]
57+ #[ build_ty = "Sig<SigShared<MidiKeyPress<MidiChannelUdp> >>" ]
4458 pub struct Props {
4559 title: String ,
4660 }
@@ -49,6 +63,21 @@ mod builder {
4963 pub fn button ( title : impl Into < String > ) -> Props {
5064 button_ ( title. into ( ) )
5165 }
66+
67+ builder ! {
68+ #[ constructor = "button_with_space_" ]
69+ #[ constructor_doc = "A visual button in a new window" ]
70+ #[ generic_setter_type_name = "X" ]
71+ #[ build_fn = "new_button_with_space" ]
72+ #[ build_ty = "ButtonWithSpace" ]
73+ pub struct PropsWithSpace {
74+ title: String ,
75+ }
76+ }
77+
78+ pub fn button_with_space ( title : impl Into < String > ) -> PropsWithSpace {
79+ button_with_space_ ( title. into ( ) )
80+ }
5281}
5382
54- pub use builder:: button;
83+ pub use builder:: { button, button_with_space } ;
0 commit comments