@@ -2,7 +2,7 @@ use crate::backend;
22use crate :: data:: {
33 self ,
44 layout:: Layout ,
5- sheet:: { Clipboard , Interval , Sheet } ,
5+ sheet:: { self , Clipboard , Pitch , Sheet } ,
66 Frame , Frame2 , Point , Range ,
77} ;
88use crate :: state:: Message as RootMessage ;
@@ -21,6 +21,7 @@ pub struct WStates {
2121 pub yrange_slider : widget:: range_slider:: State ,
2222 pub cursor : widget:: sheet_editor:: cursor:: State ,
2323 pub preview : widget:: sheet_editor:: preview:: State ,
24+ pub interval_input : Option < widget:: sheet_editor:: interval_input:: State > ,
2425}
2526
2627pub struct State {
@@ -33,7 +34,6 @@ pub struct State {
3334 pub last_tick : Instant ,
3435 pub layout : Layout ,
3536 pub tempo : f32 ,
36- pub interval_input : Interval ,
3737 pub curr_marker : usize ,
3838 pub selection : HashSet < Index > ,
3939 pub clipboard : Rc < RefCell < Clipboard > > ,
@@ -61,7 +61,6 @@ impl Default for State {
6161 last_tick : Instant :: now ( ) ,
6262 layout : Layout :: default ( ) ,
6363 tempo : 172.0 ,
64- interval_input : Interval :: Ratio ( 3 , 2 ) ,
6564 curr_marker : 0 ,
6665 selection : HashSet :: new ( ) ,
6766 clipboard : Rc :: new ( RefCell :: new ( Clipboard :: new ( ) ) ) ,
@@ -110,22 +109,36 @@ impl State {
110109 Message :: SetCursor ( at) => {
111110 self . cursor = at;
112111 }
113- Message :: AddNote ( note, mov) => {
112+ Message :: NoteAdd ( note, mov) => {
114113 let idx = self . sheet . add_note ( note) ;
115- if mov {
114+
115+ if let Pitch :: Relative ( _, _) = note. pitch {
116+ self . wstates . interval_input = Some ( widget:: sheet_editor:: interval_input:: State :: new ( & self . sheet , idx) ) ;
117+ } else if mov {
116118 let rect = note. rect ( & self . sheet , 0.0 ) ;
117119 self . wstates . board . set_action_move ( idx, rect) ;
118120 }
119121 }
120- Message :: MoveNote ( idx, pos) => {
122+ Message :: NoteMove ( idx, pos) => {
121123 self . sheet . move_note ( idx, pos. x , pos. y ) ;
122124 }
123- Message :: DeleteNote ( idx) => {
125+ Message :: NoteResize ( idx, len) => {
126+ let note = self . sheet . get_note_mut ( idx) . expect ( "tried to resize dead note" ) ;
127+ note. length = len;
128+ }
129+ Message :: NoteDelete ( idx) => {
124130 self . sheet . remove_note ( idx) ;
131+ self . wstates . interval_input = None ;
125132 }
126- Message :: ResizeNote ( idx, len) => {
127- let note = self . sheet . get_note_mut ( idx) . unwrap ( ) ;
128- note. length = len;
133+ Message :: NoteSetPitch ( idx, pitch) => {
134+ let note = self . sheet . get_note_mut ( idx) . expect ( "tried to change pitch of dead note" ) ;
135+ note. pitch = pitch;
136+ }
137+ Message :: OpenIntervalInput ( idx) => {
138+ self . wstates . interval_input = Some ( widget:: sheet_editor:: interval_input:: State :: new ( & self . sheet , idx) ) ;
139+ }
140+ Message :: CloseIntervalInput => {
141+ self . wstates . interval_input = None ;
129142 }
130143 Message :: AddMarker ( at) => {
131144 let mut new_marker = self . layout . markers [ self . curr_marker ] . clone ( ) ;
@@ -157,10 +170,13 @@ pub enum Message {
157170 Play ,
158171 CursorTick ( Instant ) ,
159172 SetCursor ( f32 ) ,
160- AddNote ( data:: sheet:: Note , bool ) , // if true: initiate move action
161- MoveNote ( data:: sheet:: Index , Point ) ,
162- ResizeNote ( data:: sheet:: Index , f32 ) ,
163- DeleteNote ( data:: sheet:: Index ) ,
173+ NoteAdd ( sheet:: Note , bool ) , // if true: initiate move action
174+ NoteMove ( sheet:: Index , Point ) ,
175+ NoteResize ( sheet:: Index , f32 ) ,
176+ NoteDelete ( sheet:: Index ) ,
177+ NoteSetPitch ( sheet:: Index , Pitch ) ,
178+ OpenIntervalInput ( sheet:: Index ) ,
179+ CloseIntervalInput ,
164180 AddMarker ( f32 ) ,
165181 SelectMarker ( usize ) ,
166182 MoveMarker ( f32 ) ,
0 commit comments