@@ -1375,32 +1375,41 @@ function Synth() {
13751375
13761376 this . _loadSample ( sourceName ) ;
13771377 if ( sourceName in this . samples . voice || sourceName in this . samples . drum ) {
1378- instruments [ turtle ] [ instrumentName ] = this . _createSampleSynth (
1379- turtle ,
1380- instrumentName ,
1381- sourceName ,
1382- params
1383- ) . toDestination ( ) ;
1378+ if ( ! instruments [ turtle ] [ instrumentName ] ) {
1379+ instruments [ turtle ] [ instrumentName ] = this . _createSampleSynth (
1380+ turtle ,
1381+ instrumentName ,
1382+ sourceName ,
1383+ params
1384+ )
1385+ }
13841386 } else if ( sourceName in BUILTIN_SYNTHS ) {
1385- instruments [ turtle ] [ instrumentName ] = this . _createBuiltinSynth (
1386- turtle ,
1387- instrumentName ,
1388- sourceName ,
1389- params
1390- ) . toDestination ( ) ;
1387+ if ( ! instruments [ turtle ] [ instrumentName ] ) {
1388+ instruments [ turtle ] [ instrumentName ] = this . _createBuiltinSynth (
1389+ turtle ,
1390+ instrumentName ,
1391+ sourceName ,
1392+ params
1393+ ) ;
1394+ }
13911395 } else if ( sourceName in CUSTOM_SYNTHS ) {
1392- instruments [ turtle ] [ instrumentName ] = this . _createCustomSynth (
1393- sourceName ,
1394- params
1395- ) . toDestination ( ) ;
1396+ if ( ! instruments [ turtle ] [ instrumentName ] ) {
1397+ instruments [ turtle ] [ instrumentName ] = this . _createCustomSynth (
1398+ sourceName ,
1399+ params
1400+ )
1401+ }
1402+
13961403 instrumentsSource [ instrumentName ] = [ 0 , "poly" ] ;
13971404 } else if ( sourceName in CUSTOMSAMPLES ) {
1398- instruments [ turtle ] [ instrumentName ] = this . _createSampleSynth (
1399- turtle ,
1400- instrumentName ,
1401- sourceName ,
1402- params
1403- ) . toDestination ( ) ;
1405+ if ( ! instruments [ turtle ] [ instrumentName ] ) {
1406+ instruments [ turtle ] [ instrumentName ] = this . _createSampleSynth (
1407+ turtle ,
1408+ instrumentName ,
1409+ sourceName ,
1410+ params
1411+ )
1412+ }
14041413 } else {
14051414 if ( sourceName . length >= 4 ) {
14061415 if ( sourceName . slice ( 0 , 4 ) === "http" ) {
@@ -1975,35 +1984,31 @@ function Synth() {
19751984 instruments [ turtle ] [ instrumentName ] . volume . value = db ;
19761985 }
19771986 } ;
1978-
1979- /**
1980- * Gets the volume of a specific instrument for a given turtle.
1981- * @function
1982- * @memberof Synth
1983- * @param {string } turtle - The name of the turtle.
1984- * @param {string } instrumentName - The name of the instrument.
1985- * @returns {number } The volume level.
1986- * @deprecated This method is currently unused and may not return correct values.
1987- */
1988- this . getVolume = ( turtle , instrumentName ) => {
1989- if ( instrumentName in instruments [ turtle ] ) {
1990- return instruments [ turtle ] [ instrumentName ] . volume . value ;
1991- } else {
1992- // eslint-disable-next-line no-console
1993- console . debug ( "instrument not found" ) ;
1994- return 50 ;
1995- }
1996- } ;
19971987
19981988 /**
19991989 * Sets the master volume for all instruments.
20001990 * @function
20011991 * @memberof Synth
20021992 * @param {number } volume - The master volume level (0 to 100).
20031993 */
2004- this . setMasterVolume = volume => {
2005- const db = Tone . gainToDb ( volume / 100 ) ;
2006- Tone . Destination . volume . rampTo ( db , 0.01 ) ;
1994+ this . setMasterVolume = ( volume , firstConnection , lastConnection ) => {
1995+ if ( ! instruments [ 0 ] [ "electronic synth" ] ) {
1996+ this . createDefaultSynth ( 0 ) ;
1997+ }
1998+ this . setVolume ( 0 , "electronic synth" , volume ) ;
1999+
2000+
2001+ if ( firstConnection === null && lastConnection === null ) {
2002+ // Reset volume to default (0 dB) first
2003+ Tone . Destination . volume . rampTo ( 0 , 0.01 ) ;
2004+ setTimeout ( ( ) => {
2005+ this . trigger ( 0 , "G4" , 1 / 4 , "electronic synth" , null , null , false ) ;
2006+ } , 200 )
2007+ }
2008+ else {
2009+ const db = Tone . gainToDb ( volume / 100 ) ;
2010+ Tone . Destination . volume . rampTo ( db , 0.01 ) ;
2011+ }
20072012 } ;
20082013
20092014 /**
0 commit comments