@@ -35,7 +35,6 @@ describe("Utility Functions (logic-only)", () => {
3535 rampTo ,
3636 DEFAULTSYNTHVOLUME ,
3737 setVolume ,
38- getVolume ,
3938 setMasterVolume ,
4039 Synth
4140
@@ -125,9 +124,7 @@ describe("Utility Functions (logic-only)", () => {
125124 stop = Synth . stop
126125 rampTo = Synth . rampTo
127126 setVolume = Synth . setVolume
128- getVolume = Synth . getVolume
129127 setMasterVolume = Synth . setMasterVolume
130-
131128 } ) ;
132129
133130
@@ -153,7 +150,7 @@ describe("Utility Functions (logic-only)", () => {
153150
154151
155152 describe ( "createDefaultSynth" , ( ) => {
156- it ( "it should creates the default poly/default/custom synth for the specified turtle" , ( ) => {
153+ it ( "it should create the default poly/default/custom synth for the specified turtle" , ( ) => {
157154 createDefaultSynth ( turtle ) ;
158155 expect ( instruments [ turtle ] [ "electronic synth" ] ) . toBeTruthy ( )
159156 expect ( instruments [ turtle ] [ "custom" ] ) . toBeTruthy ( ) ;
@@ -163,34 +160,34 @@ describe("Utility Functions (logic-only)", () => {
163160 } ) ;
164161
165162 describe ( "_createBuiltinSynth" , ( ) => {
166- it ( "it should creates a synth using builtin synths from Tone.js." , ( ) => {
163+ it ( "it should create a synth using builtin synths from Tone.js." , ( ) => {
167164 const result = _createBuiltinSynth ( turtle , "guitar" , "sine" , { } ) ;
168165 expect ( result ) . toBeInstanceOf ( Tone . Synth )
169166 } ) ;
170- it ( "it should creates a synth using builtin synths from Tone.js." , ( ) => {
167+ it ( "it should create a synth using builtin synths from Tone.js." , ( ) => {
171168 const result = _createBuiltinSynth ( turtle , "guitar" , "pluck" , { } ) ;
172169 expect ( result ) . toBeInstanceOf ( Tone . PluckSynth )
173170 } ) ;
174- it ( "it should creates a synth using builtin synths from Tone.js." , ( ) => {
171+ it ( "it should create a synth using builtin synths from Tone.js." , ( ) => {
175172 const result = _createBuiltinSynth ( turtle , "guitar" , "noise3" , { } ) ;
176173 expect ( result ) . toBeInstanceOf ( Tone . NoiseSynth )
177174 } ) ;
178175 } )
179176
180177 describe ( "_createCustomSynth" , ( ) => {
181- it ( "it should creates an amsynth using Tone.js methods like AMSynth, FMSynth, etc." , ( ) => {
178+ it ( "it should create an amsynth using Tone.js methods like AMSynth, FMSynth, etc." , ( ) => {
182179 const result = _createCustomSynth ( "amsynth" , { } ) ;
183180 expect ( result ) . toBeInstanceOf ( Tone . AMSynth ) ;
184181 } ) ;
185- it ( "it should creates a fmsynth using Tone.js methods like AMSynth, FMSynth, etc." , ( ) => {
182+ it ( "it should create a fmsynth using Tone.js methods like AMSynth, FMSynth, etc." , ( ) => {
186183 const result = _createCustomSynth ( "fmsynth" , { } ) ;
187184 expect ( result ) . toBeInstanceOf ( Tone . FMSynth ) ;
188185 } ) ;
189- it ( "it should creates a duosynth using Tone.js methods like AMSynth, FMSynth, etc." , ( ) => {
186+ it ( "it should create a duosynth using Tone.js methods like AMSynth, FMSynth, etc." , ( ) => {
190187 const result = _createCustomSynth ( "duosynth" , { } ) ;
191188 expect ( result ) . toBeInstanceOf ( Tone . DuoSynth ) ;
192189 } ) ;
193- it ( "it should creates a testsynth using Tone.js methods like AMSynth, FMSynth, etc." , ( ) => {
190+ it ( "it should create a testsynth using Tone.js methods like AMSynth, FMSynth, etc." , ( ) => {
194191 const result = _createCustomSynth ( "testsynth" , { } ) ;
195192 expect ( result ) . toBeInstanceOf ( Tone . PolySynth ) ;
196193 } ) ;
@@ -200,43 +197,43 @@ describe("Utility Functions (logic-only)", () => {
200197 beforeAll ( ( ) => {
201198 loadSamples ( )
202199 } )
203- it ( "it should creates a PolySynth based on the specified parameters, either using samples, built-in synths, or custom synths" , ( ) => {
200+ it ( "it should create a Sampler based on the specified parameters, either using samples, built-in synths, or custom synths" , ( ) => {
204201 __createSynth ( turtle , "guitar" , "guitar" , { } ) ;
205- expect ( instruments [ turtle ] [ "electronic synth " ] ) . toBeInstanceOf ( Tone . PolySynth )
202+ expect ( instruments [ turtle ] [ "guitar " ] ) . toBeInstanceOf ( Tone . Sampler )
206203 } ) ;
207- it ( "it should creates a PolySynth based on the specified parameters, either using samples, built-in synths, or custom synths" , ( ) => {
204+ it ( "it should create a Sampler based on the specified parameters, either using samples, built-in synths, or custom synths" , ( ) => {
208205 __createSynth ( turtle , "guitar" , "sine" , { } ) ;
209- expect ( instruments [ turtle ] [ "electronic synth " ] ) . toBeInstanceOf ( Tone . PolySynth )
206+ expect ( instruments [ turtle ] [ "guitar " ] ) . toBeInstanceOf ( Tone . Sampler )
210207 } ) ;
211- it ( "it should creates a amsynth based on the specified parameters, either using samples, built-in synths, or custom synths" , ( ) => {
208+ it ( "it should create a amsynth based on the specified parameters, either using samples, built-in synths, or custom synths" , ( ) => {
212209 const instrumentName = "guitar"
213210 __createSynth ( turtle , instrumentName , "amsynth" , { } ) ;
214- expect ( instruments [ turtle ] [ instrumentName ] ) . toBeInstanceOf ( Tone . AMSynth )
211+ expect ( instruments [ turtle ] [ instrumentName ] ) . toBeInstanceOf ( Tone . Sampler )
215212 } ) ;
216213
217- it ( "it should creates a CUSTOMSAMPLES based on the specified parameters, either using samples, built-in synths, or custom synths" , ( ) => {
214+ it ( "it should create a CUSTOMSAMPLES based on the specified parameters, either using samples, built-in synths, or custom synths" , ( ) => {
218215 CUSTOMSAMPLES [ 'pianoC4' ] = "pianoC4" ;
219216 CUSTOMSAMPLES [ 'drumKick' ] = "drumKick" ;
220217 const instrumentName = "guitar"
221218 __createSynth ( turtle , instrumentName , "pianoC4" , { } ) ;
222219 expect ( instruments [ turtle ] [ instrumentName ] ) . toBeInstanceOf ( Tone . Sampler )
223220 } ) ;
224221
225- it ( "it should creates a CUSTOMSAMPLES based on the specified parameters, either using samples, built-in synths, or custom synths" , ( ) => {
222+ it ( "it should create a CUSTOMSAMPLES based on the specified parameters, either using samples, built-in synths, or custom synths" , ( ) => {
226223 const instrumentName = "guitar"
227224 const sourceName = "http://testing.com"
228225 __createSynth ( turtle , instrumentName , sourceName , { } ) ;
229226 expect ( instruments [ turtle ] [ sourceName ] [ "noteDict" ] ) . toBe ( sourceName )
230227 expect ( instrumentsSource [ instrumentName ] ) . toStrictEqual ( [ 1 , 'drum' ] )
231228 } ) ;
232- it ( "it should creates a CUSTOMSAMPLES based on the specified parameters, either using samples, built-in synths, or custom synths" , ( ) => {
229+ it ( "it should create a CUSTOMSAMPLES based on the specified parameters, either using samples, built-in synths, or custom synths" , ( ) => {
233230 const instrumentName = "guitar"
234231 const sourceName = "file://testing.jpg"
235232 __createSynth ( turtle , instrumentName , sourceName , { } ) ;
236233 expect ( instruments [ turtle ] [ sourceName ] [ "noteDict" ] ) . toBe ( sourceName )
237234 expect ( instrumentsSource [ instrumentName ] ) . toStrictEqual ( [ 1 , 'drum' ] )
238235 } ) ;
239- it ( "it should creates a CUSTOMSAMPLES based on the specified parameters, either using samples, built-in synths, or custom synths" , ( ) => {
236+ it ( "it should create a CUSTOMSAMPLES based on the specified parameters, either using samples, built-in synths, or custom synths" , ( ) => {
240237 const instrumentName = "guitar"
241238 const sourceName = "drum"
242239 __createSynth ( turtle , instrumentName , sourceName , { } ) ;
@@ -496,54 +493,59 @@ describe("Utility Functions (logic-only)", () => {
496493 } ) ;
497494 } ) ;
498495
499- describe ( "getVolume function" , ( ) => {
500- beforeEach ( ( ) => {
501- jest . clearAllMocks ( ) ;
502- } ) ;
503-
504- test ( "should return the volume for a defined instrument" , ( ) => {
505- instruments . turtle1 . flute . volume . value = - 10 ;
506- const result = getVolume ( "turtle1" , "flute" ) ;
507-
508- expect ( result ) . toBe ( - 10 ) ;
509- } ) ;
510-
511- test ( "should return default volume if instrument is not found" , ( ) => {
512- const consoleSpy = jest . spyOn ( console , "debug" ) . mockImplementation ( ( ) => { } ) ;
513-
514- const result = getVolume ( "turtle1" , "nonexistent" ) ;
515-
516- expect ( result ) . toBe ( 50 ) ;
517- expect ( consoleSpy ) . toHaveBeenCalledWith ( "instrument not found" ) ;
518-
519- consoleSpy . mockRestore ( ) ;
520- } ) ;
521- } ) ;
522-
523496
524497 describe ( "setMasterVolume function" , ( ) => {
525- test ( "should set the master volume correctly" , ( ) => {
526- setMasterVolume ( 75 ) ;
498+ it ( "it should set up the Default Synth instance for 0th turtle." , ( ) => {
499+ if ( ! instruments [ 0 ] ) {
500+ instruments [ 0 ] = { } ; // Initialize instruments for the turtle
501+ }
502+ if ( ! instruments [ 0 ] [ "electronic synth" ] ) {
503+ createDefaultSynth ( 0 ) ;
504+ expect ( instruments [ 0 ] [ "electronic synth" ] ) . toBeTruthy ( ) ;
505+ }
506+
507+ } ) ;
527508
509+ test ( "should trigger electronic synth with volume 75" , ( ) => {
510+ setMasterVolume ( 75 , "c1" , null ) ;
528511 const expectedDb = Tone . gainToDb ( 0.75 ) ; // 75/100
529512 expect ( Tone . gainToDb ) . toHaveBeenCalledWith ( 0.75 ) ;
530513 expect ( Tone . Destination . volume . rampTo ) . toHaveBeenCalledWith ( expectedDb , 0.01 ) ;
531514 } ) ;
532515
533- test ( "should handle edge case with volume set to 0" , ( ) => {
534- setMasterVolume ( 0 ) ;
535-
516+ test ( "should trigger electronic synth with volume 0" , ( ) => {
517+ setMasterVolume ( 0 , "c1" , "c2" ) ;
536518 const expectedDb = Tone . gainToDb ( 0 ) ; // 0/100
537519 expect ( Tone . gainToDb ) . toHaveBeenCalledWith ( 0 ) ;
538520 expect ( Tone . Destination . volume . rampTo ) . toHaveBeenCalledWith ( expectedDb , 0.01 ) ;
539521 } ) ;
522+
523+ test ( "should handle edge case with volume set to 0 with no connections" , ( ) => {
524+ setMasterVolume ( 0 , null , null ) ;
525+ expect ( Tone . Destination . volume . rampTo ) . toHaveBeenCalledWith ( 0 , 0.01 ) ;
526+ setVolume ( 0 , "electronic synth" , 10 ) ;
527+ const expectedDb = Tone . gainToDb ( 0.1 ) ;
528+ expect ( Tone . gainToDb ) . toHaveBeenCalledWith ( 0.1 ) ;
529+ expect ( instruments [ 0 ] [ "electronic synth" ] . volume . value ) . toBe ( expectedDb ) ;
530+ // Act
531+ trigger ( 0 , "G4" , 1 / 4 , "electronic synth" , null , null , false ) ;
532+ // Assert
533+ expect ( instruments [ 0 ] [ "electronic synth" ] . triggerAttackRelease )
534+ . toHaveBeenCalledWith ( 'G4' , 1 / 4 , expect . any ( Number ) ) ;
535+ } ) ;
540536
541- test ( "should handle edge case with volume set to 100" , ( ) => {
542- setMasterVolume ( 100 ) ;
543-
544- const expectedDb = Tone . gainToDb ( 1 ) ; // 100/100
537+ test ( "should handle edge case with volume set to 100 with no connections" , ( ) => {
538+ setMasterVolume ( 100 , null , null ) ;
539+ expect ( Tone . Destination . volume . rampTo ) . toHaveBeenCalledWith ( 0 , 0.01 ) ;
540+ setVolume ( 0 , "electronic synth" , 100 ) ;
541+ const expectedDb = Tone . gainToDb ( 1 ) ;
545542 expect ( Tone . gainToDb ) . toHaveBeenCalledWith ( 1 ) ;
546- expect ( Tone . Destination . volume . rampTo ) . toHaveBeenCalledWith ( expectedDb , 0.01 ) ;
543+ expect ( instruments [ 0 ] [ "electronic synth" ] . volume . value ) . toBe ( expectedDb ) ;
544+ // Act
545+ trigger ( 0 , "G4" , 1 / 4 , "electronic synth" , null , null , false ) ;
546+ // Assert
547+ expect ( instruments [ 0 ] [ "electronic synth" ] . triggerAttackRelease )
548+ . toHaveBeenCalledWith ( 'G4' , 1 / 4 , expect . any ( Number ) ) ;
547549 } ) ;
548550 } ) ;
549551
@@ -1025,7 +1027,7 @@ describe("Utility Functions (logic-only)", () => {
10251027 } ) ;
10261028
10271029 describe ( "createSynth" , ( ) => {
1028- it ( "it should creates a synth based on the user's input in the 'Timbre' clamp, handling race conditions with the samples loader." , ( ) => {
1030+ it ( "it should create a synth based on the user's input in the 'Timbre' clamp, handling race conditions with the samples loader." , ( ) => {
10291031 expect ( createSynth ( "turtle1" , "piano" , "voiceSample1" , { } ) ) . toBe ( undefined ) ;
10301032 } ) ;
10311033 } ) ;
0 commit comments