@@ -3,12 +3,17 @@ use crate::core::{
33 AEOLIAN , C_MAJOR_PENTATONIC , DORIAN , IONIAN , LOCRIAN , LYDIAN , MIXOLYDIAN , PHRYGIAN ,
44 TET19_PENTATONIC , TET24_PENTATONIC , TET31_PENTATONIC ,
55} ;
6+ use crate :: events:: keymap:: { mode_scale_for_digit, root_midi_for_key} ;
67use crate :: overlay;
78use std:: cell:: RefCell ;
89use std:: rc:: Rc ;
910use wasm_bindgen:: JsCast ;
1011use web_sys as web;
1112
13+ thread_local ! {
14+ static MASTER_UNMUTED_GAIN : RefCell <Option <f32 >> = RefCell :: new( None ) ;
15+ }
16+
1217/// Get the name of the current scale for display purposes
1318fn get_scale_name ( scale : & [ f32 ] ) -> & ' static str {
1419 match scale {
@@ -45,37 +50,6 @@ fn update_hint_after_change(engine: &Rc<RefCell<MusicEngine>>) {
4550 }
4651}
4752
48- #[ inline]
49- pub fn root_midi_for_key ( key : & str ) -> Option < i32 > {
50- match key {
51- "a" | "A" => Some ( 69 ) , // A4
52- "b" | "B" => Some ( 71 ) , // B4
53- "c" | "C" => Some ( 60 ) , // C4 (middle C)
54- "d" | "D" => Some ( 62 ) , // D4
55- "e" | "E" => Some ( 64 ) , // E4
56- "f" | "F" => Some ( 65 ) , // F4
57- "g" | "G" => Some ( 67 ) , // G4
58- _ => None ,
59- }
60- }
61-
62- #[ inline]
63- pub fn mode_scale_for_digit ( key : & str ) -> Option < & ' static [ f32 ] > {
64- match key {
65- "1" => Some ( IONIAN ) ,
66- "2" => Some ( DORIAN ) ,
67- "3" => Some ( PHRYGIAN ) ,
68- "4" => Some ( LYDIAN ) ,
69- "5" => Some ( MIXOLYDIAN ) ,
70- "6" => Some ( AEOLIAN ) ,
71- "7" => Some ( LOCRIAN ) ,
72- "8" => Some ( TET19_PENTATONIC ) ,
73- "9" => Some ( TET24_PENTATONIC ) ,
74- "0" => Some ( TET31_PENTATONIC ) ,
75- _ => None ,
76- }
77- }
78-
7953pub fn handle_global_keydown (
8054 ev : & web:: KeyboardEvent ,
8155 engine : & Rc < RefCell < MusicEngine > > ,
@@ -141,6 +115,22 @@ pub fn handle_global_keydown(
141115 drop ( eng) ;
142116 update_hint_after_change ( engine) ;
143117 }
118+ "m" | "M" => {
119+ let current_gain = master_gain. gain ( ) . value ( ) ;
120+ if current_gain <= 0.0001 {
121+ let restored = MASTER_UNMUTED_GAIN
122+ . with ( |state| state. borrow_mut ( ) . take ( ) )
123+ . unwrap_or ( 0.25 )
124+ . clamp ( 0.0 , 1.0 ) ;
125+ _ = master_gain. gain ( ) . set_value ( restored) ;
126+ log:: info!( "[keys] master muted=false" ) ;
127+ } else {
128+ MASTER_UNMUTED_GAIN . with ( |state| * state. borrow_mut ( ) = Some ( current_gain) ) ;
129+ _ = master_gain. gain ( ) . set_value ( 0.0 ) ;
130+ log:: info!( "[keys] master muted=true" ) ;
131+ }
132+ ev. prevent_default ( ) ;
133+ }
144134 "," => {
145135 let mut eng = engine. borrow_mut ( ) ;
146136 if ev. shift_key ( ) {
0 commit comments