Discuss Scratch

Drawixe
Scratcher
14 posts

Play music note during pressing time of a button

Hello,

I would like to make a musical project, and I would like to make a sort of piano.

But by pressing a button I only can play note during a fixed number of beat and I would like the project plays the note during the pressing time of the button and WHILE I'm pressing the button (not after).

If you've a solution
gdpr533f604550b2f20900645890
Scratcher
1000+ posts

Play music note during pressing time of a button

foreverIfkeykeypressed?,thenRepeatuntilnotkeykeypressed?Playnotenotefor1beats
I think there may be a pause between each note, though.

Last edited by gdpr533f604550b2f20900645890 (July 18, 2014 21:30:49)

MoreGamesNow
Scratcher
100+ posts

Play music note during pressing time of a button

For instruments that fade fairly rapidly (e.g. a piano; instrument #1 in Scratch), this should work. I'm not sure there is a nice way to do it with instruments that offer more sustained sounds. The major drawback of this solution is that it requires 1 sprite for every note:

whenbkeypressedsetvolumeto100broadcast64waituntilnotkeybpressed?setvolumeto0whenIreceive64playnote64for2beats
gdpr533f604550b2f20900645890
Scratcher
1000+ posts

Play music note during pressing time of a button

MoreGamesNow wrote:

For instruments that fade fairly rapidly (e.g. a piano; instrument #1 in Scratch), this should work. I'm not sure there is a nice way to do it with instruments that offer more sustained sounds. The major drawback of this solution is that it requires 1 sprite for every note:

whenbkeypressedsetvolumeto100broadcast64waituntilnotkeybpressed?setvolumeto0whenIreceive64playnote64for2beats
But then, the note will only play for two beats. The note needs to play while the key is pressed. This is better:
whenbkeypressedsetvolumeto100broadcast64waituntilnotkeybpressed?WhenIreceive64Repeatuntilnotkeybpressed?Playnote64for1beats

Last edited by gdpr533f604550b2f20900645890 (July 19, 2014 08:37:12)

MoreGamesNow
Scratcher
100+ posts

Play music note during pressing time of a button

Chibi-Matoran wrote:

But then, the note will only play for two beats. The note needs to play while the key is pressed. This is better:
whenbkeypressedsetvolumeto100broadcast64waituntilnotkeybpressed?WhenIreceive64Repeatuntilnotkeybpressed?Playnote64for1beats

Your concern is certainly valid, I just don't think playing the same not over and over again is a good solution. Since on a real piano notes fade fairly quickly and don't sustain forever while you hold them, I preferred my solution.

Last edited by MoreGamesNow (July 21, 2014 04:58:23)

Drawixe
Scratcher
14 posts

Play music note during pressing time of a button

There is two problem with your both solution:
First, in your answer MoreGamesNow, when I stop pressing “b” key, the note does'nt stop in despit of the volume being 0. So note is playing 2 beats everytime I press and no matter how long I press.

Secondly, in your answer Chibi-Matoran, the note only repeat itself, a real piano doesn't do this, I want (like MoreGamesNow says) the note fades.

But I'll use your both answer for another project.

If you find any other solution ?
Drawixe
Scratcher
14 posts

Play music note during pressing time of a button

Ok your solution is valid on web version of Scratch MoreGamesNow but not on 1.4 version.

I need to work offline, I'll use this project on an event so no internet connection. Is there a solution to download the web version of scratch ?

Last edited by Drawixe (July 22, 2014 12:18:04)

stickfiregames
Scratcher
1000+ posts

Play music note during pressing time of a button

Drawixe
Scratcher
14 posts

Play music note during pressing time of a button

Doesn't work well on Ubuntu, because of Adobe Air.
Adobe Air (even in old version) doesn't work well on Ubuntu 12.04

Last edited by Drawixe (July 22, 2014 12:17:34)

MoreGamesNow
Scratcher
100+ posts

Play music note during pressing time of a button

Okay, so the problem with Scratch 1.4 is that the volume of instruments does not update for sounds already-being-played. However, it does work for recorded sounds, so one could use a script like

whenakeypressedsetvolumeto100%broadcast60waituntilnotkeyapressed?setvolumeto0%whenIreceive60playsoundnote 60untildone

The problem being that you have to import an audio file for every note
Drawixe
Scratcher
14 posts

Play music note during pressing time of a button

Yes, and for every instrument ^^'
So I've installed windows on an old computer and installed Scratch V2.

Thanks to you
scratchingboy18
Scratcher
1 post

Play music note during pressing time of a button

whenskeypressed
playsoundC piano

What I did was go into the scratch library and insert the piano notes, then I made the code above and it fixed the problem……


Last edited by scratchingboy18 (Nov. 14, 2017 23:00:51)

TTChaos
Scratcher
47 posts

Play music note during pressing time of a button

Chibi-Matoran wrote:

foreverIfkeykeypressed?thenRepeatuntilnotkeykeypressed?Playnotenotefor1beats
I think there may be a pause between each note, though.

Fixed formatting

scratchingboy18 wrote:

whenthisspriteclickedplaysoundC piano

What I did was go to the scratch library and insert the piano notes, then I made the code above and it fixed the problem……



Thanks scratchingboy18, I appreciate the help, but then you would have to upload each sound into each note.

Drawixe wrote:

Yes, and for every instrument ^^'
So I've installed windows on an old computer and installed Scratch V2.

Thanks to you
Your welcome, though I was too late
RainbowJacket1234
Scratcher
7 posts

Play music note during pressing time of a button

pointindirection
RainbowJacket1234
Scratcher
7 posts

Play music note during pressing time of a button

i know how to ask a question
askWhat's your name?andwait
ayyyyes10135
Scratcher
100+ posts

Play music note during pressing time of a button

RainbowJacket1234 wrote:

i know how to ask a question
askWhat's your name?andwait


Dont blockspam and necropost
ThunderingLions
Scratcher
13 posts

Play music note during pressing time of a button

You probably have to do something like this!

whenclickedforeverifkeyapressed?thensetinstrumenttopianoplaynotecformousedown?beats

My browser / operating system: ChromeOS 14541.0.0, Chrome 118.0.0.0, No Flash version detected

Last edited by ThunderingLions (Dec. 12, 2023 18:47:32)

ThunderingLions
Scratcher
13 posts

Play music note during pressing time of a button

ThunderingLions wrote:

Thank you very much!

I'm glad you're thanking me!

Last edited by ThunderingLions (Dec. 12, 2023 18:51:58)

Powered by DjangoBB