Discuss Scratch

Benur21
Scratcher
100+ posts

Instead of stopping all sounds, how to stop a specific sound?

Instead of stopping all sounds, how to stop a specific sound?

stop all sounds

Because I need a music always repeating when it's on the backdrop1 (example)…

when backdrop switches to [backdrop1 v]
forever

if <(backdrop name) = [backdrop1]> then

play sound [mymusic v] until done
end

end

But if the backdrop switches to backdrop2, the music will be running “until done”! And if I have other sounds I want to be running, how can I stop only the music?
I think it is a block that needs to be added…

stop sound [ v]

Last edited by Benur21 (April 1, 2016 22:28:21)

asivi
Scratcher
1000+ posts

Instead of stopping all sounds, how to stop a specific sound?

You may adjust the volume level with this block
set volume to () % // 0% to mute having this sound alone in the sprite

Last edited by asivi (April 1, 2016 22:33:33)

Benur21
Scratcher
100+ posts

Instead of stopping all sounds, how to stop a specific sound?

asivi wrote:

You may adjust the volume level with this block
set volume to () % // 0% to mute having this sound alone in the sprite

But this will set volume to 0 to all sounds, will not it? How do that block knows what sound it will set the volume to 0?
Carpit999
Scratcher
100+ posts

Instead of stopping all sounds, how to stop a specific sound?

Lets say i have 2 sounds, ‘'carrot’' and ‘'bumps’' and i want to stop only bumps, while it is 50 secs in. However, we will have to say that tempo 50 makes it 50 times as fast. So if 10 beats took 1 second, then tempo 50 would make it 500 beats a second. Assuming this is the case, you would do this:
stop all sounds
play sound [carrot v] until done
set tempo to (0) bpm
change tempo by (50)
wait (1) secs
change tempo by (-49)
You would really set the tempo to 0 bpm then set the tempo to 30000 bpm, (assuming it's 10 beats a second) because it's 500 beats in so you just multiply that by 60. So here's how it would look assuming its 10 bps:
stop all sounds
play sound [carrot v] until done
set tempo to (0) bpm
set tempo to (30000) bpm
wait (1) secs
set tempo to (600) bpm
footsocktoe
Scratcher
1000+ posts

Instead of stopping all sounds, how to stop a specific sound?

Benur21 wrote:

Instead of stopping all sounds, how to stop a specific sound?

stop all sounds

Because I need a music always repeating when it's on the backdrop1 (example)…

when backdrop switches to [backdrop1 v]
forever

if <(backdrop name) = [backdrop1]> then

play sound [mymusic v] until done
end

end

But if the backdrop switches to backdrop2, the music will be running “until done”! And if I have other sounds I want to be running, how can I stop only the music?
I think it is a block that needs to be added…

stop sound [ v]

Try this…

when backdrop switches to [backdrop1 v]
repeat until <not <(backdrop #) = [1 ]>>
play sound [ v] until done
end
gdpr533f604550b2f20900645890
Scratcher
1000+ posts

Instead of stopping all sounds, how to stop a specific sound?

footsocktoe wrote:

Try this…

when backdrop switches to [backdrop1 v]
repeat until <not <(backdrop #) = [1 ]>>
play sound [ v] until done
end
That script still has the same problem. The condition is only checked once the sound has completed.

Liam48D has a solution: https://scratch.mit.edu/projects/96146764/
Carpit999
Scratcher
100+ posts

Instead of stopping all sounds, how to stop a specific sound?

Chibi-Matoran wrote:

footsocktoe wrote:

Try this…

when backdrop switches to [backdrop1 v]
repeat until <not <(backdrop #) = [1 ]>>
play sound [ v] until done
end
That script still has the same problem. The condition is only checked once the sound has completed.

Liam48D has a solution: https://scratch.mit.edu/projects/96146764/
Nothing is wrong with mine.
footsocktoe
Scratcher
1000+ posts

Instead of stopping all sounds, how to stop a specific sound?

Chibi-Matoran wrote:

footsocktoe wrote:

Try this…

when backdrop switches to [backdrop1 v]
repeat until <not <(backdrop #) = [1 ]>>
play sound [ v] until done
end
That script still has the same problem. The condition is only checked once the sound has completed.

Liam48D has a solution: https://scratch.mit.edu/projects/96146764/

Either one wants the sound to loop over and over or one doesn't. Liam48D's solution is interesting.

Last edited by footsocktoe (April 2, 2016 18:59:13)

gdpr533f604550b2f20900645890
Scratcher
1000+ posts

Instead of stopping all sounds, how to stop a specific sound?

Carpit999 wrote:

Nothing is wrong with mine.
I don't think the tempo affects sound assets.

footsocktoe wrote:

Either one wants the sound to loop over and over or one doesn't.
Your solution does not stop a sound in the middle of it playing.
Carpit999
Scratcher
100+ posts

Instead of stopping all sounds, how to stop a specific sound?

Chibi-Matoran wrote:

Carpit999 wrote:

Nothing is wrong with mine.
I don't think the tempo affects sound assets.

footsocktoe wrote:

Either one wants the sound to loop over and over or one doesn't.
Your solution does not stop a sound in the middle of it playing.
The tempo speeds up the beats, so it is faster.
asivi
Scratcher
1000+ posts

Instead of stopping all sounds, how to stop a specific sound?

Benur21 wrote:

asivi wrote:

You may adjust the volume level with this block
set volume to () % // 0% to mute having this sound alone in the sprite

But this will set volume to 0 to all sounds, will not it? How do that block knows what sound it will set the volume to 0?
That block is only for the sounds in the sprite where you put it.
footsocktoe
Scratcher
1000+ posts

Instead of stopping all sounds, how to stop a specific sound?

Chibi-Matoran wrote:

Carpit999 wrote:

Nothing is wrong with mine.
I don't think the tempo affects sound assets.

footsocktoe wrote:

Either one wants the sound to loop over and over or one doesn't.
Your solution does not stop a sound in the middle of it playing.

Given his condition that no other sounds playing can stop, I don't think what he wants is possible.
gdpr533f604550b2f20900645890
Scratcher
1000+ posts

Instead of stopping all sounds, how to stop a specific sound?

Carpit999 wrote:

Chibi-Matoran wrote:

Carpit999 wrote:

Nothing is wrong with mine.
I don't think the tempo affects sound assets.

footsocktoe wrote:

Either one wants the sound to loop over and over or one doesn't.
Your solution does not stop a sound in the middle of it playing.
The tempo speeds up the beats, so it is faster.
I tested out the tempo blocks. Like I suspected, they only work with note blocks.
gdpr533f604550b2f20900645890
Scratcher
1000+ posts

Instead of stopping all sounds, how to stop a specific sound?

footsocktoe wrote:

Chibi-Matoran wrote:

Carpit999 wrote:

Nothing is wrong with mine.
I don't think the tempo affects sound assets.

footsocktoe wrote:

Either one wants the sound to loop over and over or one doesn't.
Your solution does not stop a sound in the middle of it playing.

Given his condition that no other sounds playing can stop, I don't think what he wants is possible.
That is what Liam48D's solution does!
asivi
Scratcher
1000+ posts

Instead of stopping all sounds, how to stop a specific sound?

Carpit999 wrote:

Lets say i have 2 sounds, ‘'carrot’' and ‘'bumps’' and i want to stop only bumps, while it is 50 secs in. However, we will have to say that tempo 50 makes it 50 times as fast. So if 10 beats took 1 second, then tempo 50 would make it 500 beats a second. Assuming this is the case, you would do this:
stop all sounds
play sound [carrot v] until done
set tempo to (0) bpm
change tempo by (50)
wait (1) secs
change tempo by (-49)
You would really set the tempo to 0 bpm then set the tempo to 30000 bpm, (assuming it's 10 beats a second) because it's 500 beats in so you just multiply that by 60. So here's how it would look assuming its 10 bps:
stop all sounds
play sound [carrot v] until done
set tempo to (0) bpm
set tempo to (30000) bpm
wait (1) secs
set tempo to (600) bpm
play drum ( v) for (0.2) beats
rest for () beats
play note ( v) for (0.5) beats
set instrument to ( v)
change tempo by ()
set tempo to (tempo) bpm
Those blocks are for midi instruments.
footsocktoe
Scratcher
1000+ posts

Instead of stopping all sounds, how to stop a specific sound?

Chibi-Matoran wrote:

footsocktoe wrote:

Chibi-Matoran wrote:

Carpit999 wrote:

Nothing is wrong with mine.
I don't think the tempo affects sound assets.

footsocktoe wrote:

Either one wants the sound to loop over and over or one doesn't.
Your solution does not stop a sound in the middle of it playing.

Given his condition that no other sounds playing can stop, I don't think what he wants is possible.
That is what Liam48D's solution does!


I know. I said Liam48D's solution was interesting. But as shown, his solution depends on sprite clicking and what OP wants is an automatic stop when the backdrop changes. Maybe I will play with it and see what I can come up with. It would be a handy ability to have.
gdpr533f604550b2f20900645890
Scratcher
1000+ posts

Instead of stopping all sounds, how to stop a specific sound?

footsocktoe wrote:

I know. I said Liam48D's solution was interesting. But as shown, his solution depends on sprite clicking and what OP wants is an automatic stop when the backdrop changes. Maybe I will play with it and see what I can come up with. It would be a handy ability to have.
*Sigh* Lemme show you how to use Liam48D's solution. The sprite-clicking was just UI in the demonstration, and the solution itself is extensible.
define Sound (id) (sound) //Instantiate clone of sprite Sound
set [id v] to (id) //Local var
set [sound v] to (sound) //Local var
create clone of [myself v]

when I start as a clone //Clone plays sound
play sound (sound)

when backdrop switches to [foobar v] //What the OP wants
stopSound [1]

define stopSound (id) //Function to stop sound
set [cloneToStop v] to [1] //Specify the clone to delete
broadcast [stopSound v] and wait

when I receive [stopSound v]
if <(id ::variables) = (cloneToStop)> then //If the clone's ID matches, delete it
delete this clone
end

Last edited by gdpr533f604550b2f20900645890 (April 2, 2016 19:21:39)

footsocktoe
Scratcher
1000+ posts

Instead of stopping all sounds, how to stop a specific sound?

Chibi-Matoran wrote:

footsocktoe wrote:

I know. I said Liam48D's solution was interesting. But as shown, his solution depends on sprite clicking and what OP wants is an automatic stop when the backdrop changes. Maybe I will play with it and see what I can come up with. It would be a handy ability to have.
*Sigh* Lemme show you how to use Liam48D's solution. The sprite-clicking was just UI in the demonstration, and the solution itself is extensible.
define Sound (id) (sound) //Instantiate clone of sprite Sound
set [id v] to (id) //Local var
set [sound v] to (sound) //Local var
create clone of [myself v]

when I start as a clone //Clone plays sound
play sound (sound)

when backdrop switches to [foobar v] //What the OP wants
stopSound [1]

define stopSound (id) //Function to stop sound
set [cloneToStop v] to [1] //Specify the clone to delete
broadcast [stopSound v] and wait

when I receive [stopSound v]
if <(id) = (cloneToStop)> then //If the clone's ID matches, delete it
delete this clone
end


Good solution!

I was hoping you would do it instead of me. Issue resolved.
gdpr533f604550b2f20900645890
Scratcher
1000+ posts

Instead of stopping all sounds, how to stop a specific sound?

Also, according to Liam's project, TheLogFather actually found the solution first.
customhacker
Scratcher
1000+ posts

Instead of stopping all sounds, how to stop a specific sound?

Powered by DjangoBB