aboutsummaryrefslogblamecommitdiff
path: root/music_sampler.py
blob: 9f14d561fe127c419f4b0955f5f05ad78ee1b1ca (plain) (tree)
1
2
3
4
5
6
7
8
9
10
          
             
              
                
 
                                        



                                
                           
                                      
                                                    
 

                                                     

                             
 
              
 
                           

                                      
                     
                           








                               
 



                                             




                                                    



                           
                                        
                                                    
                               
                                                               
                                                
                                                                      

                                                


                         
import sys
import pygame
import helpers
import threading

pygame.mixer.pre_init(frequency = 44100)
pygame.init()

size = width, height = 1024, 600

helpers.draw_lock.acquire()
screen = pygame.display.set_mode(size)
mapping = helpers.Mapping(screen, helpers.draw_lock)

action_surface = pygame.Surface((600, 250)).convert()
action_surface.fill((0,0,0))
helpers.parse_config(mapping)
helpers.draw_lock.release()

mapping.draw()

helpers.draw_lock.acquire()
screen.blit(action_surface, (10, 330))

pygame.display.flip()
helpers.draw_lock.release()

contexts = [
    'normal'
]

context = 'normal'

while 1:
    event = pygame.event.wait()

    if event.type == pygame.QUIT or (
            event.type == pygame.KEYDOWN and 
            event.mod  == 4160 and
            event.key  == pygame.K_c):
        for thread in threading.enumerate():
            if thread is threading.current_thread():
                continue
            thread.join()

        pygame.quit()
        sys.exit()

    if context == 'normal':
        if event.type == pygame.KEYDOWN:
            key = mapping.find_by_key_num(event.key)
            if key is not None:
                threading.Thread(target=key.do_actions).start()
        elif event.type == pygame.MOUSEBUTTONUP:
            key = mapping.find_by_collidepoint(pygame.mouse.get_pos())
            if key is not None:
                key.list_actions(action_surface)

    pygame.display.flip()