DoReMe song, All together.

Get help with using AutoHotkey and its commands and hotkeys
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

DoReMe song, All together.

17 May 2016, 21:57

If I click Do, Re and Me quickly, it stops previous one and plays some time later.
So, it sounds "Do Do Do Re Re Re Me (10 times), Re (7 times) and Do (7times)".
How can I make it something like Do, Re, Me, Do, Re, Me ?
Thanks.

Code: Select all

Gui, Add, Text, vDo
Gui, Add, Text, vRe
Gui, Add, Text, vMe
Gui, Add, Button,, Do
Gui, Add, Button,, Re
Gui, Add, Button,, Me
Gui, Show
Return

ButtonDo:
Do()
Return
ButtonRe:
Re()
Return
ButtonMe:
Me()
Return

Do() {
	Loop {
		i := 10 - A_Index
		GuiControl,, Do, % i
		Soundbeep, 262, 55
		Sleep, 100
	} Until !i
}
Re() {
    Loop {
		i := 10 - A_Index
		GuiControl,, Re, % i
		Soundbeep, 294, 55
		Sleep, 100
    } Until !i
}
Me() {
    Loop {
		i := 10 - A_Index
		GuiControl,, Me, % i
		Soundbeep, 330, 55
		Sleep, 100
    } Until !i
}
User avatar
boiler
Posts: 5595
Joined: 21 Dec 2014, 02:44

Re: DoReMe song, All together.

18 May 2016, 06:35

Not sure I'm understanding what you want. This is how I interpreted what you're looking to do.

Code: Select all

Stack := []

Gui, Add, Text, vDo
Gui, Add, Text, vRe
Gui, Add, Text, vMe
Gui, Add, Button,, Do
Gui, Add, Button,, Re
Gui, Add, Button,, Me
Gui, Show

Loop
	for key, Note in Stack
	{
		Play(Note)
		Stack.Remove(key)
	}

Return
 
ButtonDo:
Stack.Push("Do")
Return

ButtonRe:
Stack.Push("Re")
Return

ButtonMe:
Stack.Push("Me")
Return
 
Play(note) {
	static notes := {Do: 262, Re: 294, Me: 330}
	Loop {
		i := 10 - A_Index
		GuiControl,, %note%, % i
		Soundbeep, notes[note], 55
		Sleep, 100
	} Until !i
}
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: DoReMe song, All together.

18 May 2016, 08:42

Dear, boiler

Thanks for the nice codes.
I feel kind of guilty.
I made You wrong.
Actually, my point is "Asynchronous" coding.

Regards
User avatar
boiler
Posts: 5595
Joined: 21 Dec 2014, 02:44

Re: DoReMe song, All together.

18 May 2016, 08:50

I still don't understand. When you press the Do button, you want it to play 10 short Do beeps, right? But if you press Re before it's finished with those 10 beeps, you want it to interleave the Re beeps with the remaining Do beeps?
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: DoReMe song, All together.

18 May 2016, 09:06

Hmmm.
Let me put it another way.

I meant "fire and forget" style.

If you click "Do" button, it goes its way promptly whatsoever happens after it.
If you click "Re" button, it goes its way promptly whatsoever happens after it.
If you click "Me" button, it goes its way promptly whatsoever happens after it.

I think I make myself clear enough.
Thanks for your precious time, boiler !
User avatar
boiler
Posts: 5595
Joined: 21 Dec 2014, 02:44

Re: DoReMe song, All together.

18 May 2016, 09:25

Yes, but "whatsoever happens after it" can happen several different ways even if it's fire and forget. Your routine for playing the beeps is 10 short beeps when you press one of the buttons. If you press another button before all 10 beeps are played, do you want all the beeps to be interleaved, or are the first ones supposed to stop playing and the new ones take over?
User avatar
boiler
Posts: 5595
Joined: 21 Dec 2014, 02:44

Re: DoReMe song, All together.

18 May 2016, 09:26

Or perhaps even though your code showed 10 beeps being played when you press one of the buttons, that's not what you really wanted.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: DoReMe song, All together.

18 May 2016, 09:34

boiler wrote:Yes, but "whatsoever happens after it" can happen several different ways even if it's fire and forget. Your routine for playing the beeps is 10 short beeps when you press one of the buttons. If you press another button before all 10 beeps are played, do you want all the beeps to be interleaved, or are the first ones supposed to stop playing and the new ones take over?
If I press a button, it should start, run and finish its own codes promptly.
If I press another button while previous one is running, the previous one should not be stopped.
There is no stopping or waiting. So, You are right, now we have "interleaved beeps of two".
Finally, we could have interleaved beeps of three, if I click the third button while the previous two are still running.

Regards
User avatar
tidbit
Posts: 1170
Joined: 29 Sep 2013, 17:15
Location: USA

Re: DoReMe song, All together.

18 May 2016, 10:01

he wants multi-threading. let multiple beeps play/overlap at once without it cutting off/interrupting previous beeps, let them all finish.
or the same feature in soundplay for soundbeep: "wait | If omitted, the script's current thread will move on to the next commmand(s) while the file is playing."
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: DoReMe song, All together.

18 May 2016, 10:03

Right, tidbit
Thanks, comment.

I've read it in the Help file.
It says, "...AutoHotkey doesn't actually use multiple threads..."

I'm not so clear about "Multi-threading".
So, I did not use the term.
User avatar
boiler
Posts: 5595
Joined: 21 Dec 2014, 02:44

Re: DoReMe song, All together.

18 May 2016, 11:06

I don't think it's possible to have multiple SoundBeeps playing simultaneously like you can with audio files. If you want that, I suggest recording a wav file of each note played 10 times so you can use SoundPlay as tidbit suggested.

The best you could do with SoundBeep (as far as I know) is to interleave the multiple beeps. They would take turns and probably have a different effect than what you're looking for. But that would be possible with some modifications to the approach I laid out. It would be significantly more complex, though.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: DoReMe song, All together.

18 May 2016, 11:11

The "sound/beep/audio" is not the point here.
It's just a sample (codes) to post a question.

I'm just wondering how can I make codes which works as a "non-blocking" style.

Regards
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: DoReMe song, All together.

18 May 2016, 11:39

It is a "Blocking" codes;

Code: Select all

FileDelete, Result.txt
Gui, Add, Button,, Do
Gui, Add, Button,, Re
Gui, Add, Button,, Me
Gui, Add, Button,, ShowMeFile
Gui, Show
Return

ButtonDo:
Do()
Return
ButtonRe:
Re()
Return
ButtonMe:
Me()
Return
ButtonShowMeFile:
Run, Result.txt,, 	Max
Return

Do() {
	Loop, 10
	{
		FileAppend,% "Do_" A_Index "`n", Result.txt	
		Sleep, 100
	}
}
Re() {
	Loop, 10
	{
		FileAppend,% "Re_" A_Index "`n", Result.txt	
		Sleep, 100
	}
}
Me() {
	Loop, 10
	{
		FileAppend,% "Me_" A_Index "`n", Result.txt	
		Sleep, 100
	}
}
I'd like to make a "Non-blocking" codes.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: DoReMe song, All together.

18 May 2016, 11:46

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
"Result : Blocking"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Do_1
Do_2
Do_3
Do_4
Re_1
Re_2
Re_3
Re_4
Re_5
Me_1
Me_2
Me_3
Me_4
Me_5
Me_6
Me_7
Me_8
Me_9
Me_10
Re_6
Re_7
Re_8
Re_9
Re_10
Do_5
Do_6
Do_7
Do_8
Do_9
Do_10


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
"Result : Non-Blocking" (Something like this)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Do_1
Do_2
Do_3
Do_4
Re_1
Do_5
Re_2
Do_6
Re_3
Do_7
Re_4
Do_8
Re_5
Do_9
Me_1
Re_6
Do_10
Me_2
Re_7
Me_3
Re_8
Me_4
Re_9
Me_5
Re_10
Me_6
Me_7
Me_8
Me_9
Me_10

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], tatagi, Xtra and 34 guests