Example #1
0
def print_lrc(mixer, lrc_d, color, wholetime):
    mixer.play()
    # 防止开头歌词来不及播放
    mixer.pause()
    time.sleep(0.001)
    mixer.play()
    while 1:
        # 截取到0.1s精度,降低cpu占用
        t = mixer.seconds() / 100 * 100
        sys.stdout.write('[' +
                         time.strftime("%M:%S", time.localtime(t / 1000)) +
                         '/' +
                         time.strftime("%M:%S", time.localtime(wholetime)) +
                         '] ')
        if t in lrc_d:
            sys.stdout.write(color + lrc_d[t] + '\033[0m')
            sys.stdout.flush()
            # 向后清除
            sys.stdout.write("\033[K")
        else:
            sys.stdout.flush()
            # 向后清除
            # sys.stdout.write("\033[K")
        sys.stdout.write('\r')
        # 播放停止时退出
        if t < 0:
            sys.exit(0)
        # 0.05s循环
        time.sleep(0.05)
Example #2
0
def pause_sound():
    """
    Pauses all sound channels. Equivalent to `pygame.mixer.pause()`.
    """
    try:
        mixer.pause()
    except pygame.error:
        pass
Example #3
0
 def player_pause(self) -> None:
     pmixer.pause()
     self.player_status = PlayerStatus.PAUSED
     self.ui.btn_pause_play.setIcon(
         QtGui.QIcon(
             str(Path(BASE_PATH, self.cfg.svg_path,
                      self.cfg.svg_btn_play))))
     self.ui.btn_pause_play.clicked.disconnect()
     self.ui.btn_pause_play.clicked.connect(self.player_unpause)
Example #4
0
 def speak_pygame(self):
     mixer.init()
     mixer.pause()
     mixer.music.load(self.speak_result)
     mixer.music.play()
     self.hibernate()
     mixer.music.stop()
     mixer.unpause()
     mixer.quit()
Example #5
0
 def speak_pygame(self):
     mixer.init()
     mixer.pause()
     mixer.music.load(self.speak_result)
     mixer.music.play()
     self.hibernate()
     mixer.music.stop()
     mixer.unpause()
     mixer.quit()
Example #6
0
 def pauseSound(self):
     global paused
     if(paused == False):
         paused = True
         mixer.pause()
         print("pausing")
     else:
         paused = False
         mixer.unpause()
         print("unpausing")
Example #7
0
 def pauseSound(self):
     global paused
     if (paused == False):
         paused = True
         mixer.pause()
         print("pausing")
     else:
         paused = False
         mixer.unpause()
         print("unpausing")
Example #8
0
def play_music(stop, pause_sound=False):
    global current_sound
    try:
        sound_file = "sounds/"+str(stop.attrs["sd"]).strip(string.whitespace)
        if not pause_sound:
            mix.pause()
            current_sound = mix.Sound(sound_file)
            logging.info('music loaded')
            current_sound.play()
        else:
            mix.pause()
    except:
        print "No music found"
def write_primary_speaker(current_file):
    try:
        basename = current_file.split('/')[-1].split('_sec_')[0]
        if basename[-6:] == '.16000':
            basename = basename[:-6]
        time_in = str(
            float(current_file.split('_sec_')[-1].replace('.wav', '')))
        csv_writer.writerow([basename, time_in, '1.0', speaker_value, ''])
    except:
        print("ERROR: " + current_file)
    time.sleep(0.1)
    mixer.pause()
    mixer.init()
    play_sound()
Example #10
0
    def pause(self):
        """<DOC>
		Pauses playback (if any).
		
		Example:
		>>> from openexp.sampler import sampler
		>>> src = exp.get_file('my_sound.ogg')
		>>> my_sampler = sampler(exp, src)
		>>> my_sampler.play()
		>>> self.sleep(100)
		>>> my_sampler.pause()				
		>>> self.sleep(100)
		>>> my_sampler.resume()				
		</DOC>"""

        mixer.pause()
Example #11
0
    def pause(self):

        """<DOC>
		Pauses playback (if any).

		Example:
		>>> from openexp.sampler import sampler
		>>> src = exp.get_file('my_sound.ogg')
		>>> my_sampler = sampler(exp, src)
		>>> my_sampler.play()
		>>> self.sleep(100)
		>>> my_sampler.pause()
		>>> self.sleep(100)
		>>> my_sampler.resume()
		</DOC>"""

        mixer.pause()
Example #12
0
    def next(self):
        '''
        Move the game forward by 1 frame

        Passes state objects to the teams and pass their actions to ```move_next()```

        Also checks for special keyboard buttons and sets internal flags to pause, quit
        the game or run it in debug mode
        '''
        a1 = self.team1.move(self.state_prev, self.state, self.rewards)
        a2 = self.team2.move(self.state_prev, self.state, self.rewards)

        pause_flag = any([a == 'PAUSE' for a in a1])
        quit_flag  = any([a == 'QUIT' for a in a1])
        form_flag  = any([a == 'TOGGLE_FORM' for a in a1])
        debug_flag = any([a == 'TOGGLE_DEBUG' for a in a1])

        if quit_flag:
            mixer.pause()
            if self.sound:
                three_whistles.play()
            self.end = True
            #pygame.quit()

        if pause_flag:
            self.pause = not self.pause
            if self.pause:
                mixer.pause()
                if self.sound:
                    single_long_whistle.play()
            else:
                if self.sound:
                    single_short_whistle.play()
                    applause.play(-1)

        if form_flag:
            self.team1.maintain_formation = not self.team1.maintain_formation

        if debug_flag:
            mods = pygame.key.get_mods()
            if mods & pygame.KMOD_CTRL and mods & pygame.KMOD_SHIFT and mods & pygame.KMOD_ALT:
                self.debug = not self.debug

        if not self.pause:
            self.state_prev, self.state, self.rewards = self.move_next(a1, a2)
 def joyCB(self, msg):
     self.on_1 = bool(msg.buttons[0])
     self.on_2 = bool(msg.buttons[1])
     self.on_3 = bool(msg.buttons[2])
     self.on_4 = bool(msg.buttons[3])
     self.counter_reset = bool(msg.buttons[6])
     if self.on_1 == True:
         self.playing_sound(1)
     elif self.on_2 == True:
         self.playing_sound(2)
     elif self.on_3 == True:
         self.playing_sound(3)
     elif self.on_4 == True:
         self.playing_sound(4)
     elif self.counter_reset == True:
         self.counter_1 = 1
         self.counter_2 = 1
         self.counter_3 = 1
         self.counter_4 = 1
         mixer.pause()
         print "Done --------- Counter-Reset"
 def playing_sound(self, num):
     if num == 1:
         if self.counter_1 == 1:
             self.sound_1.set_volume(self.volume_1)
             mixer.pause()
             self.sound_1.play()
             self.counter_1 = 0
             print "playing --------- " + str(self.sound_file_1)
     if num == 2:
         if self.counter_2 == 1:
             self.sound_2.set_volume(self.volume_2)
             self.sound_2.play()
             self.counter_2 = 0
             print "playing --------- " + str(self.sound_file_2)
     if num == 3:
         if self.counter_3 == 1:
             self.sound_3.set_volume(self.volume_3)
             mixer.pause()
             self.sound_3.play()
             self.counter_3 = 0
             print "playing --------- " + str(self.sound_file_3)
     if num == 4:
         if self.counter_4 == 1:
             self.sound_4.set_volume(self.volume_4)
             mixer.pause()
             self.sound_4.play()
             self.counter_4 = 0
             print "playing --------- " + str(self.sound_file_4)
Example #15
0
    def check_interruptions(self):
        """
        Check for special keyboard buttons

        Sets internal flags to pause, quit the game or run it in debug mode
        """
        for event in pygame.event.get():
            if event.type == pygame.QUIT:  # Quit
                mixer.pause()
                if self.sound:
                    three_whistles.play()
                self.end = True
                pygame.quit()

            if event.type == pygame.KEYDOWN:

                if event.key == pygame.K_ESCAPE:  # Pause menu
                    self.pause = not self.pause
                    if self.pause:
                        mixer.pause()
                        if self.sound:
                            single_long_whistle.play()
                    else:
                        if self.sound:
                            single_short_whistle.play()
                            applause.play(-1)

                if event.key == pygame.K_BACKSPACE:  # Return to main menu
                    mixer.stop()
                    self.end = True

                if event.key == pygame.K_SPACE:  # Toggle whether to maintain formation
                    self.team1.maintain_formation = not self.team1.maintain_formation

                if event.key == pygame.K_d:  # Debug mode
                    mods = pygame.key.get_mods()
                    if mods & pygame.KMOD_CTRL and mods & pygame.KMOD_SHIFT and mods & pygame.KMOD_ALT:
                        self.debug = not self.debug
Example #16
0
 def _pause(self):
     pm.pause()
     self.paused = True
Example #17
0
        player_x = 0
    elif player_x >= 736:
        player_x = 736

    '# Enemy Movement'
    for i in range(num_of_enemies):

        '# Ending the Game'
        if enemy_y[i] > 487:
            for j in range(num_of_enemies):
                enemy_y[j] = 1100
                player_x = 2090
                player_y = 2090
                mixer.music.load('spacewar.mp3')
                mixer.music.stop()
                bullet_sound = mixer.pause()
            end_text()
            font = pygame.font.Font('freesansbold.ttf', 40)
            text_x = 290
            text_y = 200
            break

        enemy_x[i] += enemy_x_change[i]
        if enemy_x[i] <= 0:
            enemy_x_change[i] = 2.5
            enemy_y[i] += enemy_y_change[i]
            if score_value >= 100:
                enemy_x_change[i] = 3
                enemy_y[i] += enemy_y_change[i]
                if score_value >= 300:
                    enemy_x_change[i] = 4
Example #18
0
def write_yes():
    fo.write('''"''' + current_file + '''"''' + ', correct\n')
    time.sleep(0.1)
    mixer.pause()
    mixer.init()
    play_sound()
Example #19
0
def pause_sound():
    try:
        mixer.pause()
    except pygame.error:
        pass
Example #20
0
 def set_menu_sound(self, name, val):
     if self.sound and not val:
         mixer.pause()
     elif not self.sound and val:
         mixer.unpause()
     self.sound = val
Example #21
0
    def __init__(self, resolution=(800, 720), fps=60):
        M = 1024  # Slice size

        # Load the song
        songName = "backstage.mp3"

        # Number of FFT bar groups
        self.num_groups = 31

        song = Audio.Audio_fft(songName, M=M, group_num=self.num_groups)

        self.max_amp = song.max_amp
        self.max_amp_raw = song.max_amp_raw

        # Initalise visualiser
        pygame.init()
        # Initialize mixer
        pygame.mixer.quit()
        pygame.mixer.init(frequency=song.rate)
        pygame.mixer.music.load(songName)
        pygame.mixer.music.play(0)

        clock = pygame.time.Clock()
        self.screen = pygame.display.set_mode(resolution)

        # Close the program if the user clicks the close button
        done = False
        while not done:
            self.screen.fill(pygame.Color('white'))

            song_time = pygame.mixer.music.get_pos()

            for event in pygame.event.get():
                if (event.type == 2):
                    mixer.pause()
                    time.sleep(2)
                    mixer.unpause()
                if event.type == pygame.QUIT:
                    done = True

            seconds = song_time / 1000

            try:
                scale = int(np.floor(song.rate / M * seconds))
                slice_num = [M * (scale), M * (scale + 1)]

                self.draw_fourier(
                    song.get_fft(slice_num, grouped=True, localAvg=False))
                self.draw_raw(song.get_wave(slice_num))

            except ValueError:
                break

            # Titles on the screen
            FrequencyTitle = pygame.font.Font(None, 30).render(
                "Frequency Spectrum of the Song", True, pygame.Color('black'))
            TimeTitle = pygame.font.Font(None,
                                         30).render("Song Frequency", True,
                                                    pygame.Color('black'))

            self.screen.blit(FrequencyTitle, (260, 320))
            self.screen.blit(TimeTitle, (320, 690))

            # Update the screen
            pygame.display.flip()
            clock.tick(fps)

        pygame.quit()
Example #22
0
    def run(self):

        timer = pygame.time.Clock()
        last_frame_time = 0.0

        for world in self.worlds:

            world.engine = self

            # load the scene of the world before running
            world.start_scene_loading()

            render_system = world.get_system(RenderSystem.tag)

            # failed to obtain the render system
            if render_system is None:
                print("Error. Render system does not exist in the world.")
                return

            # construct the scene order from the initial entities
            render_system.construct_scene(world.entity_manager.entities)

        while True:

            # do not run the game if delta time is too high
            if self.delta_time >= 0.05:
                self.delta_time = 0.0
                continue

            # Get the initial time in milliseconds of the current frame
            frame_start_time = pygame.time.get_ticks()

            if self.print_fps:
                print("FPS: ", timer.get_fps(), "delta time: ",
                      self.delta_time)

            if self.world is None:
                print("Error, the world specified is None.")
                Engine.clean_up()

            # poll input events
            for event in pygame.event.get():
                if event.type == QUIT:
                    Engine.clean_up()

                # key down presses
                elif event.type == pygame.KEYDOWN:

                    # pause the game
                    if event.key == pygame.K_p:
                        self.paused = not self.paused

                        # pause/resume audio
                        if self.paused:
                            mixer.pause()
                            mixer.music.pause()
                        else:
                            mixer.unpause()
                            mixer.music.unpause()

                    # toggle debug mode
                    elif event.key == pygame.K_F12:
                        self.debug = not self.debug

                    elif event.key == pygame.K_F11:
                        self.print_fps = not self.print_fps

                # pass input events to the world
                if not self.paused:
                    self.world._take_input(event)

            # Run the currently set world
            if not self.paused:
                self.world.run()

            # draw gui elements on top of everything
            self.gui.draw_widgets()

            pygame.display.update()

            # The time interval between this frame and the last one.
            # Convert the time from milliseconds to seconds
            self.delta_time = (frame_start_time - last_frame_time) / 1000.0
            last_frame_time = frame_start_time
            timer.tick(self.fps)
def main(highest_score):
    # Game initialization
    pygame.init()
    screen = pygame.display.set_mode(config.SCREENSIZE)
    pygame.display.set_caption('Running Dinosaur - ghodei')
    # Import audio files
    sounds = {}
    for key, value in config.AUDIO_PATHS.items():
        sounds[key] = pygame.mixer.Sound(value)
    # Start game interface
    StartGameInterface(screen, sounds, config)
    # Define some variables and resources in the game
    score = 0
    score_board = Scoreboard(config.IMAGE_PATHS['numbers'],
                             position=(534, 15),
                             bg_color=config.BACKGROUND_COLOR)
    highest_score = highest_score
    highest_score_board = Scoreboard(config.IMAGE_PATHS['numbers'],
                                     position=(435, 15),
                                     bg_color=config.BACKGROUND_COLOR,
                                     is_highest=True)
    dinosaur = Dinosaur(config.IMAGE_PATHS['dinosaur'])
    ground = Ground(config.IMAGE_PATHS['ground'],
                    position=(0, config.SCREENSIZE[1]))
    cloud_sprites_group = pygame.sprite.Group()
    cactus_sprites_group = pygame.sprite.Group()
    pterodactyl_sprites_group = pygame.sprite.Group()
    add_obstacle_timer = 0
    score_timer = 0
    # Game main loop
    clock = pygame.time.Clock()
    pygame.mixer.init()
    pygame.mixer.music.load("resources/audios/music.wav")
    pygame.mixer.music.play(loops=-1)
    pygame.display.update()
    clock.tick(15)

    # Pause variable definition
    def pause():
        pause_image = pygame.image.load(config.IMAGE_PATHS['pause'])
        pause_image = pygame.transform.scale(pause_image, (150, 15))
        pause_image_rect = pause_image.get_rect()
        pause_image_rect.centerx = config.SCREENSIZE[0] / 2
        pause_image_rect.centery = config.SCREENSIZE[1] * 0.45
        paused = True
        while paused:
            pygame.mixer.music.pause()
            screen.blit(pause_image, pause_image_rect)
            pygame.display.update()
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    sys.exit()
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_SPACE or event.key == pygame.K_UP:
                        paused = False
                        pygame.mixer.music.unpause()
                    elif event.key == pygame.K_ESCAPE:
                        pygame.quit()
                        quit()
                    elif event.key == pygame.K_r:
                        pygame.mixer.music.stop()
                        main(highest_score)

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_p:
                    pause()
                elif event.key == pygame.K_SPACE or event.key == pygame.K_UP:
                    dinosaur.jump(sounds)
                elif event.key == pygame.K_DOWN:
                    dinosaur.duck()
                elif event.key == pygame.K_ESCAPE:
                    pygame.quit()
                    sys.exit()
            elif event.type == pygame.KEYUP and event.key == pygame.K_DOWN:
                dinosaur.unduck()
        screen.fill(config.BACKGROUND_COLOR)
        # Add clouds randomly
        if len(cloud_sprites_group) < 5 and random.randrange(0, 300) == 10:
            cloud_sprites_group.add(
                Cloud(config.IMAGE_PATHS['cloud'],
                      position=(config.SCREENSIZE[0], random.randrange(30,
                                                                       75))))
        # Add cactus and pterodactyl randomly
        add_obstacle_timer += 1
        if add_obstacle_timer > random.randrange(50, 150):
            add_obstacle_timer = 0
            random_value = random.randrange(0, 10)
            if random_value >= 1 and random_value <= 5:
                cactus_sprites_group.add(Cactus(config.IMAGE_PATHS['cactus']))
            else:
                position_ys = [
                    config.SCREENSIZE[1] * 0.82, config.SCREENSIZE[1] * 0.75,
                    config.SCREENSIZE[1] * 0.60, config.SCREENSIZE[1] * 0.20
                ]
                pterodactyl_sprites_group.add(
                    Pterodactyl(config.IMAGE_PATHS['pterodactyl'],
                                position=(600, random.choice(position_ys))))
        # Update game resources
        dinosaur.update()
        ground.update()
        cloud_sprites_group.update()
        cactus_sprites_group.update()
        pterodactyl_sprites_group.update()
        score_timer += 1
        if score_timer > (config.FPS // 12):
            score_timer = 0
            score += 1
            score = min(score, 99999)
            if score > highest_score:
                highest_score = score
            if score % 100 == 0:
                sounds['points'].play()
        # Check impact
        for item in cactus_sprites_group:
            if pygame.sprite.collide_mask(dinosaur, item):
                dinosaur.die(sounds)
        for item in pterodactyl_sprites_group:
            if pygame.sprite.collide_mask(dinosaur, item):
                dinosaur.die(sounds)
        # Draw game resources on the screen
        ground.draw(screen)
        cloud_sprites_group.draw(screen)
        dinosaur.draw(screen)
        cactus_sprites_group.draw(screen)
        pterodactyl_sprites_group.draw(screen)
        score_board.set(score)
        highest_score_board.set(highest_score)
        score_board.draw(screen)
        highest_score_board.draw(screen)
        # Update screen
        pygame.display.update()
        clock.tick(config.FPS)
        # Check if the game is over
        if dinosaur.is_dead:
            break
    # Game over interface
    return EndGameInterface(screen, config), highest_score
Example #24
0
 def pause(self):
     return mixer.pause()
Example #25
0
 def onPause(self):
     mixer.pause()
Example #26
0
def pause_sound():
    try:
        mixer.pause()
    except pygame.error:
        pass
Example #27
0
 def play_stream(self,recvdQ, datAvail, shutdown, pause_event, client):
     mixer.init()
     channel = None
     hasLock = False
     end = False
     self.remote_play.set()
     print('playstream active')
     while self.remote_play.is_set() and not shutdown.is_set():#if flag cleared this will hault playback
         #print('playing')
         #print('sample:',data[0:99],len(data))
         if not pause_event.is_set():#stops when user requests pause
             mixer.pause()
             pause_event.wait()
             mixer.unpause()
         if not hasLock:
             #print('wait on datavail')
             hasLock = datAvail.acquire()
             #print('datavail aquired')
         try:
             if recvdQ.full():
                 if channel is None:
                     recvd = recvdQ.get()
                     if len(recvd) > 0:
                         data = recvd.pop(0)
                         recvdQ.put(recvd)
                         if data == 'end' and not channel.get_busy():
                             hasLock = False
                             datAvail.release()
                             break
                         sound = mixer.Sound(buffer = data)
                         #print('first sound buffed')
                         channel = sound.play()
                         channel.pause()
                         hasLock = False
                         datAvail.release()
                     else:
                         #print('wait on data - init')
                         recvdQ.put(recvd)
                         datAvail.wait()
                         #print('init awkoen')
                 else:
                     if not channel.get_queue(): 
                         recvd = recvdQ.get()
                         if len(recvd) > 0 and not end:
                             #print('addnl sound buffed',len(recvd), 'available' )
                             data = recvd.pop(0)
                             recvdQ.put(recvd)
                             #print(data[:2])
                             if data == 'end':
                                 #print('!!!')
                                 end = True
                             if end and not channel.get_busy():
                                 #print('end play')
                                 break
                             channel.queue(mixer.Sound(buffer = data))
                             channel.unpause()
                             hasLock = False
                             datAvail.release()
                         elif end:
                             while True:
                                 #print('addnl sound buffed',len(recvd), 'available' )
                                 data = recvd.pop(0)
                                 channel.queue(mixer.Sound(buffer = data))
                                 channel.unpause()
                                 if not channel.get_busy():
                                    break
                                 recvdQ.put(recvd)
                                 hasLock = False
                                 datAvail.release()
                                 break
                         else:
                             recvdQ.put(recvd)
                             #print('wait on data')
                             datAvail.wait()
                             #print('data awoken')
                     else:
                         #print('wait on queue')
                         hasLock = False
                         datAvail.release()
         except Exception as e: 
             print(e)
             hasLock = False
             datAvail.release()
             pass
     if channel is not None:
         if channel.get_busy():
             channel.stop()
     print('termination our of loop')
     self.remote_play.clear()
     recvd = recvdQ.get()#clear the recieved in case user terminated
     if recvdQ is []:#naturally terminated
         self.func_stream_next() #calls passed function from GUI to play next song
     else:
         print('sending stopper')
         client.sendall(b'S')
         client.close()
     recvdQ.put([])
     recvdQ.put(recvd)
Example #28
0
from pygame import mixer

op = '0'

print('\nOlá meu querido amigo')
while op[0] != 'N':
    ht = '0'
    ht = str(input('Você está triste hoje? ')).strip().upper()
    mixer.init()
    mixer.pause()
    if ht[0] == 'S':
        mixer.init()
        mixer.music.load('fds.mp3')
        mixer.music.play()
        print('Não mais')
        op = str(input('Quer dar outra resposta? ')).strip().upper()

    elif ht[0] == 'N':
        mixer.init()
        mixer.music.load('trn.mp3')
        mixer.music.set_volume(0.3)
        mixer.music.play()
        print(
            'Que bom! Que o dia continue feliz meu gigante pela própria natureza'
        )
        op = str(input('Quer dar outra resposta? ')).strip().upper()
print('Volte sempre')
    def main_loop(self):
        # Close the program if the user clicks the close button
        done = False
        frame_count = 0

        prev_seconds = 0
        prev_ccc = np.array([[[0, 0, 0] for j in range(self.jump_fps - 1)]
                             for i in range(1, self.N)])
        shift = 0

        while not done:
            frame_count += 1
            self.screen.fill(pygame.Color('white'))

            song_time = pygame.mixer.music.get_pos()

            for event in pygame.event.get():
                if (event.type == 2):
                    mixer.pause()
                    time.sleep(2)
                    mixer.unpause()
                if event.type == pygame.QUIT:
                    done = True

            seconds = song_time / 1000

            try:
                if frame_count == 1:
                    scale = int(np.floor(self.song.rate / self.M * seconds))
                    #print(prev_seconds,seconds)
                    prev_scale = int(
                        np.floor(self.song.rate / self.M * (prev_seconds)))
                    slice_num = [self.M * (scale), self.M * (scale + 1)]
                    prev_slice = [
                        self.M * (prev_scale), self.M * (prev_scale + 1)
                    ]

                    shift += random.randint(-1, 1)
                    curr_fft = self.song.get_fft(slice_num,
                                                 grouped=True,
                                                 localAvg=False)
                    prev_fft = self.song.get_fft(prev_slice,
                                                 grouped=True,
                                                 localAvg=False)
                    inner_vals = self.interpolate.calc(prev_fft, curr_fft)
                    prev_seconds = seconds
                    ccc = []
                    for i in range(1, self.N):
                        tmp_h_curr = curr_fft[i]
                        if tmp_h_curr > self.width_height[
                                1] - self.left_top[0] // 2:
                            tmp_h_curr = self.width_height[
                                1] - self.left_top[0] // 2

                        # print(tmp_h_curr,tmp_h_prev)
                        if tmp_h_curr > 0:
                            v = (tmp_h_curr / (self.width_height[1] -
                                               self.left_top[0] // 2)) * 15
                        else:
                            v = 0
                        if v > 1:
                            v = 1
                        tmp_rgb = self.hsv_to_rgb(
                            (shift + i) % self.N / (self.N), 0.5, v)
                        tmp_vals = self.interpolate.calc(
                            prev_ccc[i - 1][-1], tmp_rgb)
                        ccc.append(tmp_vals)
                    prev_ccc = ccc
            except ValueError:
                break

            # Set colour for each bar
            for i in range(1, self.N):
                self.bars[i - 1].colour = prev_ccc[i - 1][frame_count - 1]

            self.draw_fourier(inner_vals[frame_count - 1])
            self.draw_raw(self.song.get_wave(slice_num))
            # Titles on the screen
            FrequencyTitle = pygame.font.Font(None, 30).render(
                "Frequency Spectrum of the Song", True, pygame.Color('black'))
            TimeTitle = pygame.font.Font(None,
                                         30).render("Song Frequency", True,
                                                    pygame.Color('black'))

            self.screen.blit(FrequencyTitle, (260, 320))
            self.screen.blit(TimeTitle, (320, 690))

            # Update the screen
            pygame.display.flip()
            self.clock.tick(self.fps)
            if frame_count == self.jump_fps:
                frame_count = 0
        pygame.quit()
Example #30
0
    def run(self):

        timer = pygame.time.Clock()
        last_frame_time = 0.0

        for world in self.worlds:

            world.engine = self

            # load the scene of the world before running
            world.start_scene_loading()

            render_system = world.get_system(RenderSystem.tag)

            # failed to obtain the render system
            if render_system is None:
                print("Error. Render system does not exist in the world.")
                return

            # construct the scene order from the initial entities
            render_system.construct_scene(world.entity_manager.entities)

        while True:

            # do not run the game if delta time is too high
            if self.delta_time >= 0.05:
                self.delta_time = 0.0
                continue

            # Get the initial time in milliseconds of the current frame
            frame_start_time = pygame.time.get_ticks()

            if self.print_fps:
                print("FPS: ", timer.get_fps(), "delta time: ", self.delta_time)

            if self.world is None:
                print("Error, the world specified is None.")
                Engine.clean_up()

            # poll input events
            for event in pygame.event.get():
                if event.type == QUIT:
                    Engine.clean_up()

                # key down presses
                elif event.type == pygame.KEYDOWN:

                    # pause the game
                    if event.key == pygame.K_p:
                        self.paused = not self.paused

                        # pause/resume audio
                        if self.paused:
                            mixer.pause()
                            mixer.music.pause()
                        else:
                            mixer.unpause()
                            mixer.music.unpause()

                    # toggle debug mode
                    elif event.key == pygame.K_F12:
                        self.debug = not self.debug

                    elif event.key == pygame.K_F11:
                        self.print_fps = not self.print_fps

                # pass input events to the world
                if not self.paused:
                    self.world._take_input(event)

            # Run the currently set world
            if not self.paused:
                self.world.run()

            # draw gui elements on top of everything
            self.gui.draw_widgets()

            pygame.display.update()

            # The time interval between this frame and the last one.
            # Convert the time from milliseconds to seconds
            self.delta_time = (frame_start_time - last_frame_time)/1000.0
            last_frame_time = frame_start_time
            timer.tick(self.fps)
Example #31
0
def speech_control(command):
    if command == 'pause':
        mixer.pause()
    if command == 'stop':
        mixer.stop()
Example #32
0
 def pause(self):
     mixer.pause()
Example #33
0
	def pause(self):

		mixer.pause()