This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2009-04-09 09:36:22

samaga
Scratcher
Registered: 2009-04-07
Posts: 8

How to adjust dinamically the duration of a note?

I have just posted a simple project called Pianichi.
But, I am not satisfied with it.

It is very simple.

[blocks]
<when[  ]key pressed>
<play note(  )for(  )secss>
[/blocks]

However, the duration of each note is fixed.

In fact what I want is that the note sounds while key remains pressed and stops when it will be released.

Is it possible todo that?

I have done some tests using a variable for beats and putting it to zero with another thread script, but without success.

Last edited by samaga (2009-04-09 11:04:00)

Offline

 

#2 2009-04-09 09:45:32

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: How to adjust dinamically the duration of a note?

You can probably make it work by having the note play for a very long time - and then interrupt it with a Stop All Sounds when the key is released.  Similar to this project

http://scratch.mit.edu/projects/Paddle2SeeFixIt/431745


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#3 2009-04-09 10:06:01

samaga
Scratcher
Registered: 2009-04-07
Posts: 8

Re: How to adjust dinamically the duration of a note?

Thank you Paddle2See,

but that will stop abrupty all sounds you were playing at this moment.
I want to stop only this sound.
(You can be playing some notes and a time and only want to stop one).

Also this an abrupt stop. In fact I want the final of the note to be soft, like a real piano.

Maybe that is not possible...

Last edited by samaga (2009-04-09 10:07:20)

Offline

 

#4 2009-04-09 21:19:14

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: How to adjust dinamically the duration of a note?

I don't know of another way.  Sorry.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#5 2009-04-10 06:18:05

samaga
Scratcher
Registered: 2009-04-07
Posts: 8

Re: How to adjust dinamically the duration of a note?

Paddle2See wrote:

I don't know of another way.  Sorry.

Do not worry Paddle2See.
Thank you in any case!

Offline

 

#6 2009-04-11 18:08:42

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: How to adjust dinamically the duration of a note?

Hi samaga,

I usually get around the problem you're describing by calling the stack with the unfinished note again. Let me give you an example:

Make one stack play a (variable) note for a long time:

   when I receive 'play note'
   play note (variable) for 10 beats

Make another stack call the 'play note' stack, even if it is not finished yet:

   when I receive 'play song'
   set 'index' to 0
   repeat (length of 'song')
      change 'index' by 1
      set 'variable' to (item 'index' of 'song')
      broadcast 'play note'
      rest (item 'index' of 'durations')
   end


Jens Mönig

Offline

 

Board footer