Thursday, October 21, 2010

Pygame

Alex from the Bubble Pop Electric team suggested Pygame to program the music suit, so I explored a little bit with the coding.

Pygame provide python modules that can be constructed to create multimedia games. The music module provides a set of commands of audio that could be useful for reading the manipulations on the suit.

pygame.mixer.music.load(filename): return None 
This command will load the audio indicated. This action should be executed when a music bubble is turned on. However, the drawback is that it will stop the clip already playing, and we need a system that can play multiple tracks at once.


pygame.mixer.music.get_pos(): return time
The get_pos command returns the time the music has been playing for. This value is useful to position additional music clips that will have to sync with the music that is already playing. For example, if the tempo of the music is indicated to have measures that are 4 seconds each, the additional clip that is activated by the player can be programmed to come in at the nearest time characterized by multiples of 4. If the user plays a beat bubble while a main song is playing, the computer calculates the main music's time by using:
pygame.mixer.music.get_pos(): return time

If the return value is divisible by four, the beat music will play immediately through
pygame.mixer.music.play(loops=0, start=0.0): return None

If it is not divisible by three, the computer retrieves the value of the remainder, subtract that number from 4, wait for that many seconds and then play the clip.

This scenario is highly theoretical, but this study will hopefully help me visualize the programming aspect of the TUI.


Source:
http://www.pygame.org/news.html
http://www.pygame.org/docs/ref/music.html

No comments:

Post a Comment