1
1
/*
2
2
* JSS-01 |JavaScript Software Synthesizer
3
- * Copyright (c) 2023 Michael Kolesidis <michael.kolesidis@gmail.com>
3
+ * Copyright (c) Michael Kolesidis <michael.kolesidis@gmail.com>
4
4
* GNU Affero General Public License v3.0
5
5
*
6
6
*/
@@ -14,7 +14,10 @@ import { assertNotNull } from '../utils/utils.js';
14
14
import displaysUI from '../elements/displays/displays.ui.js' ;
15
15
16
16
// @todo
17
- import { getInterface as getKeyboardUI , handlers as keyboardHandlers } from '../elements/keyboard/keyboard.js' ;
17
+ import {
18
+ getInterface as getKeyboardUI ,
19
+ handlers as keyboardHandlers ,
20
+ } from '../elements/keyboard/keyboard.js' ;
18
21
19
22
import createSynth from './synth.js' ;
20
23
import createSynthHandlers from './synth.handlers.js' ;
@@ -26,72 +29,72 @@ let synth: PolySynth<FMSynth>;
26
29
let destination : Destination ;
27
30
28
31
async function createContext ( ) {
29
- const { start, getDestination, Midi } = await import ( './tone.js' ) ;
32
+ const { start, getDestination, Midi } = await import ( './tone.js' ) ;
30
33
31
- await start ( ) ;
32
- // console.log('started tone context');
34
+ await start ( ) ;
35
+ // console.log('started tone context');
33
36
34
- destination = getDestination ( ) ;
37
+ destination = getDestination ( ) ;
35
38
36
- assertNotNull ( displaysUI . oscilloscope ) ;
37
- assertNotNull ( displaysUI . spectrogram ) ;
38
- assertNotNull ( displaysUI . meter ) ;
39
+ assertNotNull ( displaysUI . oscilloscope ) ;
40
+ assertNotNull ( displaysUI . spectrogram ) ;
41
+ assertNotNull ( displaysUI . meter ) ;
39
42
40
- displaysUI . oscilloscope . connect ( destination as unknown as AudioNode ) ;
41
- displaysUI . spectrogram . connect ( destination as unknown as AudioNode ) ;
42
- displaysUI . meter . connect ( destination as unknown as AudioNode , 1 ) ;
43
+ displaysUI . oscilloscope . connect ( destination as unknown as AudioNode ) ;
44
+ displaysUI . spectrogram . connect ( destination as unknown as AudioNode ) ;
45
+ displaysUI . meter . connect ( destination as unknown as AudioNode , 1 ) ;
43
46
44
- // apply ui settings to audio node
45
- synth = await createSynth ( ) ;
46
- synth . toDestination ( ) ;
47
+ // apply ui settings to audio node
48
+ synth = await createSynth ( ) ;
49
+ synth . toDestination ( ) ;
47
50
48
- // add ui handlers
49
- createSynthHandlers ( ) ;
50
- createSequencerHandlers ( ) ;
51
+ // add ui handlers
52
+ createSynthHandlers ( ) ;
53
+ createSequencerHandlers ( ) ;
51
54
52
- createEffects ( ) ;
55
+ createEffects ( ) ;
53
56
54
- // ---------------------------------------------------------------------
55
- // Synthesizer On-Screen Keyboard Playbility Implementation
56
- // ---------------------------------------------------------------------
57
- // Polyphonic synths need a note or an array of notes
57
+ // ---------------------------------------------------------------------
58
+ // Synthesizer On-Screen Keyboard Playbility Implementation
59
+ // ---------------------------------------------------------------------
60
+ // Polyphonic synths need a note or an array of notes
58
61
59
- const keyboard = getKeyboardUI ( ) ;
62
+ const keyboard = getKeyboardUI ( ) ;
60
63
61
- let notes : string [ ] = [ ] ;
64
+ let notes : string [ ] = [ ] ;
62
65
63
- keyboard . on ( 'change' , async ( note ) => {
64
- const noteString = Midi ( note . note ) . toNote ( ) ;
65
- // console.log(noteString);
66
+ keyboard . on ( 'change' , async ( note ) => {
67
+ const noteString = Midi ( note . note ) . toNote ( ) ;
68
+ // console.log(noteString);
66
69
67
- if ( note . state ) {
68
- synth . triggerAttack ( noteString ) ;
69
- notes . push ( noteString ) ;
70
- } else {
71
- synth . triggerRelease ( note . note ) ;
72
- notes = notes . filter ( ( e ) => e !== noteString ) ;
73
- }
74
- } ) ;
70
+ if ( note . state ) {
71
+ synth . triggerAttack ( noteString ) ;
72
+ notes . push ( noteString ) ;
73
+ } else {
74
+ synth . triggerRelease ( note . note ) ;
75
+ notes = notes . filter ( ( e ) => e !== noteString ) ;
76
+ }
77
+ } ) ;
75
78
76
- // keydown and keyup event
77
- // => alternate octave / change keyboard interface state
78
- for ( const [ event , handler ] of Object . entries ( keyboardHandlers ) ) {
79
- document . addEventListener ( event , handler ) ;
80
- }
79
+ // keydown and keyup event
80
+ // => alternate octave / change keyboard interface state
81
+ for ( const [ event , handler ] of Object . entries ( keyboardHandlers ) ) {
82
+ document . addEventListener ( event , handler ) ;
83
+ }
81
84
}
82
85
83
86
export default {
84
- create : createContext ,
85
- get ( ) {
86
- return {
87
- synth,
88
- destination,
89
- } ;
90
- } ,
91
- getSynth ( ) {
92
- return synth ;
93
- } ,
94
- getDestination ( ) {
95
- return destination ;
96
- } ,
87
+ create : createContext ,
88
+ get ( ) {
89
+ return {
90
+ synth,
91
+ destination,
92
+ } ;
93
+ } ,
94
+ getSynth ( ) {
95
+ return synth ;
96
+ } ,
97
+ getDestination ( ) {
98
+ return destination ;
99
+ } ,
97
100
} ;
0 commit comments