Pygame Play Sounds Blocking - pygame

i am trying to play sounds with pygame sound. My code is this:
from tkinter import *
import pygame
root= Tk()
pygame.init()
bass = pygame.mixer.Sound('sounds\\bass.wav')
snare = pygame.mixer.Sound('sounds\snare.wav')
crash = pygame.mixer.Sound('sounds\crash.wav')
bass.play()
snare.play()
crash.play()
root.mainloop()
When i run this code all three wave files are played together.
I want to play them one after the other, and possibly have control over the time difference between each successive sounds .
What is an elegant way to do this ?
Thanks a lot for replying.

The pygame.mixer.music module allows you to queue files to play, although I don't know of how you could specify a buffer between sounds.
http://www.pygame.org/docs/ref/music.html#pygame.mixer.music.queue
pygame.mixer.music.load('sounds\bass.wav')
pygame.mixer.music.queue('sounds\snare.wav')
pygame.mixer.music.queue('sounds\crash.wav')
pygame.mixer.music.play()
Just be aware that mixer.music streams the audio, unlike the mixer.Sound object which will load the entire file first.

Related

How to output a .pvd or xdmf file from FiPy

From the example documentation, there is the following section:
FiPy doesn’t plot or output anything unless you tell it to:
if __name__ == "__main__":
viewer = Viewer(vars=(phi,), datamin=0., datamax=1.)
I understand that the current configuration would result in an opening of a viewer using the matplotlib or Mayavi viewers. However, I would like to be able to export a .pvd or .xdmf file for consolidating the simulation.
Thanks for your help!
FiPy presently has no such capability, although I've experimented a bit with XDMF and multi-timestep Gmsh MSH files, but need to find time to get back to it. You can save individual data snapshots with the VTKViewer classes, but not time series.
vw = fp.VTKCellViewer(vars=(phi, psi))
vw.plot(filename="myFile.vtk")
If there are particular thinks you'd like to see, please update issue #132.

Flash Professional CC stuck on publishing swf from huge .fla

My .fla is about 600mb big due to enormous amount of library objects.
I have 15.500 objects in library and most of them are images. This is probably bad practice, but my client required to have these images inside of it instead of loading them dynamically from some external source.
I have already reduced the size of the images as much as possible while still maintaining good quality.
I'm publishing for Flash Player, and already tried different versions.
Basicly my app is fairly simple test paper app, populating 20 test papers with simple multiple choise questions. Each test paper has 150 questions divided into 4 sections, and each question contains 1 question image and 4 answer images to choose from. After user picks his/her answer, these image instances are being deleted and new ones are being created.
I've heard that there's magical limit of 16.000 for everything like instances and so on, so it should stay right about under it as the code itself is quite simple and there's not many other instances after these images.
Besides my ugly file size, I'm also pushing all these images from library into arrays in a loop:
(linkage names are for example "Paper1_Chem_Q1_C.jpg", and "_X" marks the correct answer - that's why I unshift that one)
var sectionLengths:Array = [40,40,45,25];
var prefixes:Array = ["Phys","Chem","Maths","Eng_Reas"];
var prefixes2:Array = ["A","B","C","D"];
for(var p:int = 0; p<20; p++){ //test papers loop
for(var s:int = 0; s<4; s++){ //sections loop
var fillQArray:Array = this["tp"+(p+1)+"section"+(s+1)+"questions"];
var fillAArray:Array = this["tp"+(p+1)+"section"+(s+1)+"answers"];
for(var q:int = 0; q<sectionLengths[s]; q++){ //question loop
if(ApplicationDomain.currentDomain.hasDefinition(String("Paper"+(p+1)+"_"+prefixes[s]+"_Q"+(q+1)))){
fillQArray.push(getDefinitionByName("Paper"+(p+1)+"_"+prefixes[s]+"_Q"+(q+1)) as Class);
var qa:Array = new Array();
for(var a:int = 0; a<4; a++){ //answers loop
if(ApplicationDomain.currentDomain.hasDefinition(String("Paper"+(p+1)+"_"+prefixes[s]+"_Q"+(q+1)+"_"+prefixes2[a]))){
qa.push(getDefinitionByName("Paper"+(p+1)+"_"+prefixes[s]+"_Q"+(q+1)+"_"+prefixes2[a]));
}else if(ApplicationDomain.currentDomain.hasDefinition(String("Paper"+(p+1)+"_"+prefixes[s]+"_Q"+(q+1)+"_"+prefixes2[a]+"_X"))){
qa.unshift(getDefinitionByName("Paper"+(p+1)+"_"+prefixes[s]+"_Q"+(q+1)+"_"+prefixes2[a]+"_X"));
}
}
fillAArray.push(qa);
}
}
}
}
This loop surely does the job, but takes some time to run. Also, I predefine a LOT of arrays before it, so can this be another potential issue?
During development I've tested everything with few test papers, and it all worked like a charm, but now when I imported all the rest of the images, it gets stuck on publish. I left it to publish for the whole night, but now at morning it's once again stuck and I have to kill Flash process in order to quit it.
I have also increased memory amount from jvm.ini already to 2048m, so it doesn't give anymore the warning dialog regarding to too small JVM memory.
All suggestions are more than welcome.
I finally got it working, thanks to Vesper!
Here's detailed instructions for Flash Professional CC (so detailed becouse this was all new to me, and I spent almost 2 days for this failing multiple times):
Step 1 - Publish SWC:
Create empty .fla and import your images to library. Select all the
images and open properties with mouse2 button. At ActionScript tab
select Export for ActionScript. Make sure that also Export in frame 1 is activated.
Define a Classname for your project at Properties panel, for example: images_swc.
Go to Publish Settings and publish only SWC.
Notes:
In my case I had to create 3 SWC files becouse of the amount of images (15000+).
While adding/removing large amount of images to/from library, and while publishing a SWC, Flash Professional stopped responding and it looked like a crash, but in 30-60mins it succesfully finished!
When it was over an hour in "not responding" -state, I killed Flash process and tried with smaller amount of images.
First I created my "empty" .fla by removing everything but images from my main project, but somehow it didn't export correct images during SWC publish. But after I Saved As.. my image project, it worked like a charm.
Always when Flash notified about low JVM memory, I doubled the memory value in jvm.ini and started over. (Had eventually 4096m.)
Step 2 - Use SWC in your main project:
File -> Publish Settings -> Advanced ActionScript 3.0 Settings (wrench -icon at top-right-corner) -> Library path tab -> Click Browse to SWC file, locate your SWC and click OK.
Create empty .as file and type every image classname into it. Idea here is to mention all the images from SWC so that compiler understands that you want to include them in your main project. e.g:
package {
public class Assets {
image_1;
image_2;
image_3;
}
}
In your main project, include Assets.as and your SWC-file(s):
import Assets;
import images_swc;
Refer to your images with:
getDefinitionByName("image_1")
Final notes:
If you forget your "SWC classname", change the extension of your SWC file to .zip, open it, and you'll find your classname and other details from the xml file inside of it.
To get filenames of large amount of images for your .as file (assuming you have same classnames and filenames for your images), you can use windows command prompt and "dir /s > filename.txt" -command to gether filenames into txt-file. Myself I used free version of Directory List & Print which also finds files from subfolders, pasted the file list into Assets.as and used Find & Replace functionality in Flash to replace ".jpg" with ";".
So, I had over 15000 images, turned them into 3 SWC files = 15-20 megs per SWC, and my final .swf was around 55 megs - and it was compiled in couple minutes, which makes this pretty perfect solution for my project.
#Vesper, thanks again! :)

Flash CC wont embed image assets

I have this code on the first frame of the timeline:
import flash.display.Bitmap;
[Embed("letter.jpg")]
const Letter:Class;
var letter:Bitmap = new Letter();
addChild(letter);
I get this compile time error:
Scene 1, Layer 'Layer 1', Frame 1, Line 1, Column 1 1120: Access of undefined property MainTimeline_Letter.
I have tried many ways, but I cant get Flash CC or Flash Builder to compile. The image file is in the same directory. What am I doing wrong? Please help.
Here are the source files: FILES
I try it with an MP3, and it works fine...
import flash.media.Sound;
[Embed("coffee.mp3")]
var Coffee:Class;
var snd:Sound = new Coffee();
snd.play();
Thoughts???
Update:
FYI I am on a Macbook Pro OS X 10.7.5 Using Adobe Flash CC
Finally found the answer! Please go to:
/Users/"YOURNAME"/Library/Application Support/Adobe/Flash CC/
Delete everything! It should work without the undefined property error. Worth a try. Good luck!
I ended up uninstalling Flash and reinstalling it after dealing with this for 3 days. It worked on on the first run. Thanks Adobe :-(
Update:
Flash CC told me that the my memory was low in the jvm.ini file, but it rendered the embedded image on stage and you can see it. But I changed the value to 512 from 256. I closed Flash, then I reopened it. Thats when I got the compiletime error I've been wrestling with. I changed it back to 256, but then the image doesnt render on the stage (back to square 1). I am going to abandon this method and just load everything as external assets.

Where is Tween in AS3

It seems mx.transitions.Tween has be replaced in AS3 as I get a compiler error.
Does anyone know what is it replaced with or where is Tween moved?
According to the Adobe AS3 docs, it's fl.transitions.Tween.
You really couldn't Google that yourself?
I'm new to ActionScript. I'm using Flash Professional CS5. While I'm coding, when I enter the code like new Tween= it will import the header.
So there is Tween class in AS3 and its called fl.transitions.Tween;
You also need to import fl.transitions.ease.*; because the syntax of the Tween will use ease.
I use tweenLite for my tweens.
It's fast, reliable and easy to use.
such as:
import com.greensock.*;
TweenLite.to(mc, 1, {x:65, y:117});
You can find more information at http://www.greensock.com/tweenlite/
you have to import the ans one package and your project should contain fla file....

How can I 'force download' a file that has been generated entirely in Flash?

If I'm generating a binary file inside Flash Player, how do I pop up a 'Save' dialog for the file without sending it up the the server first?
I'm sure I heard this was a new feature in Flash 10.
Cheers,
James
This will help, and really show you how to do it, all you have to keep in mind is that opening and saving files can only be done with user initiation, it cannot be automated, so not sure what you are trying to do, but this will help:
http://www.mikechambers.com/blog/2008/08/20/reading-and-writing-local-files-in-flash-player-10/
If you are inside the flash player, you can do the following:
import flash.net.FileReference;
import flash.utils.ByteArray;
var fileReference:FileReference = new FileReference();
var data:ByteArray; // load up your data into this ByteArray
fileReference.save(data, "outputfile.dat");
This will not work if you are running in the browser-- at least as far as I remember, but if you are in the flash player this will work.
The FileReference.save() method will popup a dialog for the user to choose where to save the file, so the filename given is just a suggested filename.
Edit: See Technomaag's comment below also if you're having problems