def play(self, fenetre): fenetre.clear(sf.Color.White) for i in range(len(tableau)): sf.draw(tableau[i]) sf.display() sf.sleep(temps)
def gerer_fps(temps_actuel): print(temps_actuel.elapsed_time.milliseconds) if temps_actuel.elapsed_time.milliseconds < 30: sf.sleep(sf.milliseconds(30-temps_actuel.elapsed_time.milliseconds)) temps_actuel.restart()
def thread(self, sound, volume, loops=0): sound.play() sound.volume = rint(volume) # loop while the sound is playing time = 0 killtime = 0 deltat = 10 while sound.status in (sfml.Sound.PLAYING, sfml.Sound.PAUSED): # leave some CPU time for other processes sfml.sleep(sfml.milliseconds(deltat)) time += deltat if sound.fadein and time < sound.fadein: sound.volume = rint(volume * float(time) / sound.fadein) if sound.fadeout and time > sound.duration - sound.fadeout: sound.volume = rint(volume * float(time) / (rint(volume * float(time) / sound.fadein))) if not sound.kill_in is None: killtime += deltat if killtime > sound.kill_in: sound.stop() sound.kill_in = None break else: sound.volume *= 1 - float(killtime / sound.kill_in) if loops > 0: self.thread(sound, volume, loops - 1) if self.permanent == sound: self.thread(sound, volume) elif self.permanent and sound.typ == "music": self.thread(self.permanent, volume)
def setUp(self): self.port = randint(10000, 65000) self.server_manager = None self.server_started = False def server_thread(test_case): test_case.server_manager = ServerManager(config_object={'network':{'port': self.port}}) def on_run(): test_case.server_started = True test_case.server_manager.on_run = on_run dbs = test_case.server_manager.db_session_type() dbs.add(User(name='john', password='******')) dbs.add(User(name='lazy', password='')) dbs.add(GamePawn(name='test_pawn', width=2, height=3, shapestring="100110")) dbs.add(GameBoard(name='test_board', width=6, height=8, shapestring="0"*48)) dbs.flush() test_case.server_manager.run() self.server_thread = Thread(target=server_thread, args=(self,)) self.server_thread.start() while not self.server_started: sleep(milliseconds(10)) sleep(milliseconds(100))
def gerer_fps(temps_actuel): print(temps_actuel.elapsed_time.milliseconds) if temps_actuel.elapsed_time.milliseconds < 30: sf.sleep(sf.milliseconds(30 - temps_actuel.elapsed_time.milliseconds)) temps_actuel.restart()
def _sfml(s_file, times=None, fadeout=None): global FRAMERATE sound = sf.Music.from_file(s_file) for t in range(times): sound.play() while sound.status == sf.Music.PLAYING: sf.sleep(sf.milliseconds(FRAMERATE))
def utiliser(self, fenetre): fenetre.clear(sf.Color.White) # Chaque image est affichée un certain temps for i in range(len(self.tableau)): sf.draw(self.tableau[i]) sf.display() sf.sleep(self.temps)
def __playMusicFromFile(self, music_file): if not self.pausing: self.music = sf.Music.from_file(music_file) ## Play it self.music.play() #loop while the sound is playing while self.music.status == sf.Music.PLAYING: #leave some cpu time for other processes sf.sleep(sf.milliseconds(100))
def main(): # check that the device can capture audio if not sf.SoundRecorder.is_available(): print("Sorry, audio capture is not supported by your system") return # choose the sample rate sample_rate = int(input("Please choose the sample rate for sound capture (44100 is CD quality): ")) # wait for user input... input("Press enter to start recording audio") # here we'll use an integrated custom recorder, which saves the captured data into a sf.SoundBuffer recorder = sf.SoundBufferRecorder() # audio capture is done in a separate thread, so we can block the main thread while it is capturing recorder.start(sample_rate) input("Recording... press enter to stop") recorder.stop() # get the buffer containing the captured data buffer = recorder.buffer # display captured sound informations print("Sound information:") print("{0} seconds".format(buffer.duration)) print("{0} samples / seconds".format(buffer.sample_rate)) print("{0} channels".format(buffer.channel_count)) # choose what to do with the recorded sound data choice = input("What do you want to do with captured sound (p = play, s = save) ? ") if choice == 's': # choose the filename filename = input("Choose the file to create: ") # save the buffer buffer.to_file(filename); else: # create a sound instance and play it sound = sf.Sound(buffer) sound.play(); # wait until finished while sound.status == sf.Sound.PLAYING: # leave some CPU time for other threads sf.sleep(sf.milliseconds(100)) # finished ! print("Done !") # wait until the user presses 'enter' key input("Press enter to exit...")
def play_music(): # load an ogg music file music = sf.Music.from_file("data/orchestral.ogg") # display music informations print("orchestral.ogg:") print("{0} seconds".format(music.duration)) print("{0} samples / sec".format(music.sample_rate)) print("{0} channels".format(music.channel_count)) # play it music.play() # loop while the music is playing while music.status == sf.Music.PLAYING: # leave some CPU time for other processes sf.sleep(sf.milliseconds(100))
def play_sound(): # load a sound buffer from a wav file buffer = sf.SoundBuffer.from_file("data/canary.wav") # display sound informations print("canary.wav:") print("{0} seconds".format(buffer.duration)) print("{0} samples / sec".format(buffer.sample_rate)) print("{0} channels".format(buffer.channel_count)) # create a sound instance and play it sound = sf.Sound(buffer) sound.play() # loop while the sound is playing while sound.status == sf.Sound.PLAYING: # leave some CPU time for other processes sf.sleep(sf.milliseconds(100))
def do_server(port): # build an audio stream to play sound data as it is received through the network audio_stream = NetworkAudioStream() audio_stream.start(port) # loop until the sound playback is finished while audio_stream.status != sf.SoundStream.STOPPED: # leave some CPU time for other threads sf.sleep(sf.milliseconds(100)) # wait until the user presses 'enter' key input("Press enter to replay the sound...") # replay the sound (just to make sure replaying the received data is OK) audio_stream.play(); # loop until the sound playback is finished while audio_stream.status != sf.SoundStream.STOPPED: sf.sleep(sf.milliseconds(100))
def on_get_data(self, chunk): # we have reached the end of the buffer and all audio data have been played : we can stop playback if self.offset >= len(self.samples) and self.has_finished: return False # no new data has arrived since last update : wait until we get some while self.offset >= len(self.samples) and not self.has_finished: sf.sleep(sf.milliseconds(10)) # don't forget to lock as we run in two separate threads lock = threading.Lock() lock.acquire() # fill audio data to pass to the stream chunk.data = self.samples.data[self.offset*2:] # update the playing offset self.offset += len(chunk) lock.release() return True
def setUp(self): self.port = randint(10000, 65000) self.server_manager = None self.server_started = False def server_thread(test_case): test_case.server_manager = ServerManager(config_object={'network':{'port': self.port}}) def on_run(): test_case.server_started = True test_case.server_manager.on_run = on_run dbs = test_case.server_manager.db_session_type() dbs.add(User(name='john', password='******')) dbs.add(User(name='lazy', password='')) dbs.flush() test_case.server_manager.run() self.server_thread = Thread(target=server_thread, args=(self,)) self.server_thread.start() while not self.server_started: sleep(milliseconds(10)) sleep(milliseconds(100))
menubar = self.menuBar() file_menu = menubar.addMenu('&File') file_menu.addAction(new_game) file_menu.addAction(close_action) self.setGeometry(500, 500, 500, 500) self.setWindowTitle('pedeRPG') self.show() def main(): app = QtGui.QApplication(sys.argv) menu = Menu() sys.exit(app.exec_()) if __name__ == '__main__': main() RESOLUTION = 1024, 768 WALLPAPER = 'f****t.png' TITLE = "Placeholder for shitfuck" window = sf.RenderWindow(sf.VideoMode(*RESOLUTION), TITLE) texture = sf.Texture.from_file(WALLPAPER) sprite = sf.Sprite(texture) window.draw(sprite) window.display() sf.sleep(sf.seconds(5))