Player choice - sending commands to 2 objects that do the same thing?

Visuals, audio, animation. Blended, not stirred. If LiveCode is part of your rich media production toolbox, this is the forum for you.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
dalkin
Posts: 101
Joined: Wed Jul 04, 2007 2:32 am
Location: Blackheath, Australia
Contact:

Player choice - sending commands to 2 objects that do the same thing?

Post by dalkin » Mon Mar 23, 2020 4:16 am

Image

At the moment, I record a sound (Record1, Record2, Record3 etc.), stop the recording (Stop1, 2, 3 etc) and play the sound (tSound) with button Play1, Play2, Play3 etc) and it plays to the end .. All working fine and not a problem but it plays to the end without any user controls which could be problematic with longer sounds, in which case it would be far better to ALSO have the playback controlled by the Player object, which I just added.

I am having trouble also sending the sound to Player P1 to allow users to Start/Stop the sound if it's longer and set up an environment where they can play a short sound (Play1) or a long sound (Player object P1).

The 'Record' script on button Record1 is:

Code: Select all

on mouseUp
   put the cUserDefinedRecordingFolder of this card into tUserFolder
      
   ## User did not define a folder yet:
   if there is not a folder tUserFolder then
      answer folder "Select a folder for the recordings:"
      if the result is cancel then
         exit to top
      end if
      ## We store the folder also in a custom property:
      set the cUserDefinedRecordingFolder of this stack to IT      
      ## We need this in this script:
      put it into tUserFolder
   end if
   
   set the recordFormat to "wav"
   ask "Please name the recording:"
   if it = empty then
      exit to top
   end if
   put it into tUserDefinedName
   put tUserFolder & "/" & tUserDefinedName & ".wav" into tFile
   
   ## Now set two custom properties fo the PLAY1 button, so the button knows what to play when clicked!
   set the cAudioFile of btn "play1" to tFile
   set the cUserDefinedName of btn "play1" to tUserDefinedName
   mergMicrophoneStartRecording tFile
   set the label of button "Record1" to "Recording"
   ##

end mouseUp
And the Play1 script is:

Code: Select all

on mouseUp
   put the cAudioFile of me into tFile
   put the cUserDefinedName of me into tUserDefinedName
   if tFile = EMPTY then
      ## Nothing recorded yet!
      exit to top
   end if
   play tFile
   set the label of button "Play1" to "Playing"
   wait until the sound is done
   set the label of button "Play1" to "Play1"
   ##
end mouseUp
Attachments
test.livecode.zip
(2.92 KiB) Downloaded 31 times
Screen Shot 2020-03-23 at 1.19.34 pm.png
Last edited by dalkin on Mon Mar 23, 2020 10:02 am, edited 1 time in total.
If you're skating on thin ice you might as well dance.

bogs
Posts: 4678
Joined: Sat Feb 25, 2017 10:45 pm

Re: Player choice - sending commands to 2 objects that do the same thing?

Post by bogs » Mon Mar 23, 2020 9:54 am

Heya dalkin.

Not for nothing, and I don't see any problems with the scripts posted code wise, but would you mind wrapping them in a code block? It formats them a bit better for the forums, and they don't take up so much space since the code blocks have scrollbars.

All that you would have to do to your post above is highlight the code, then click the button above the editor that says "Code display:",
aPic_codeBlock.png
Code block, like writer's block, but better!
and it allows formatting of code as well as condensing of space, as well as a quick way to copy the code out by selecting all of it in one cilck ~

Code: Select all

on mouseUp
	put the cUserDefinedRecordingFolder of this card into tUserFolder

	## User did not define a folder yet:
	if there is not a folder tUserFolder then
	   answer folder "Select a folder for the recordings:"
	      if the result is cancel then
		exit to top
	      end if
	   ## We store the folder also in a custom property:
	   set the cUserDefinedRecordingFolder of this stack to IT 
	   ## We need this in this script:
	   put it into tUserFolder
	end if
Other than that, neato on the code :D
Image

dalkin
Posts: 101
Joined: Wed Jul 04, 2007 2:32 am
Location: Blackheath, Australia
Contact:

Re: Player choice - sending commands to 2 objects that do the same thing?

Post by dalkin » Mon Mar 23, 2020 10:03 am

Thanks so much ... very neato!
If you're skating on thin ice you might as well dance.

bogs
Posts: 4678
Joined: Sat Feb 25, 2017 10:45 pm

Re: Player choice - sending commands to 2 objects that do the same thing?

Post by bogs » Mon Mar 23, 2020 10:18 am

Thank YOU!! So much easier to read for these tired old eyes Image
Image

dalkin
Posts: 101
Joined: Wed Jul 04, 2007 2:32 am
Location: Blackheath, Australia
Contact:

Re: Player choice - sending commands to 2 objects that do the same thing?

Post by dalkin » Tue Mar 24, 2020 12:59 am

I found the solution by abandoning the concept of sending signals to 2 objects and settled on the player object.
On the Record button

Code: Select all

on mouseUp
   put the cUserDefinedRecordingFolder of this card into tUserFolder
   
   ## User did not define a folder yet:
   if there is not a folder tUserFolder then
      answer folder "Select a folder for the recordings:"
      if the result is cancel then
         exit to top
      end if
      ## We store the folder also in a custom property:
      set the cUserDefinedRecordingFolder of this stack to IT      
      ## We need this in this script:
      put it into tUserFolder
   end if
   
   set the recordFormat to "wav"
   ask "Please name the recording:"
   if it = empty then
      exit to top
   end if
   put it into tUserDefinedName
   put tUserFolder & "/" & tUserDefinedName & ".wav" into tFile
   
   ## Now set two custom properties fo the PLAY1 button, so the button knows what to play when clicked!
   set the cAudioFile of btn "play1" to tFile
 [b]  set the filename of player "P1" to tFile[/b]
   set the cUserDefinedName of btn "play1" to tUserDefinedName
   mergMicrophoneStartRecording tFile
   set the label of button "Record1" to "Recording"
   ##
   
end mouseUp
On the Play button:

Code: Select all

on mouseUp
   put the cAudioFile of me into tFile
[b]   set the filename of player "P1" to tFile[/b]
   put the cUserDefinedName of me into tUserDefinedName
   if tFile = EMPTY then
      ## Nothing recorded yet!
      exit to top
   end if
 [b]  start player "P1"[/b]
   ##play tFile
   set the label of button "Play1" to "Playing"
   wait until the sound is done
   set the label of button "Play1" to "Play1"
   ##
end mouseUp
If you're skating on thin ice you might as well dance.

Post Reply

Return to “Multimedia”