]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blame - music_sampler.py
Use kivy instead of pygame
[perso/Immae/Projets/Python/MusicSampler.git] / music_sampler.py
CommitLineData
d8ab67c7 1import sys
189bf90c 2import pygame
189bf90c 3import helpers
e7f8dab4 4import threading
189bf90c 5
8f88a3e4 6pygame.mixer.pre_init(frequency = 44100)
189bf90c
IB
7pygame.init()
8
9de92b6d 9size = width, height = 913, 563
189bf90c 10screen = pygame.display.set_mode(size)
9de92b6d 11screen.fill((229, 228, 226))
ba9ea93a
IB
12
13draw_lock = helpers.Lock("draw")
189bf90c 14
ba9ea93a 15mapping = helpers.Mapping(screen, draw_lock)
9de92b6d 16channel_number, open_files = helpers.parse_config(mapping)
d479af33 17pygame.mixer.set_num_channels(channel_number)
8f88a3e4 18
e7f8dab4 19mapping.draw()
189bf90c 20
ba9ea93a 21draw_lock.acquire()
189bf90c 22pygame.display.flip()
ba9ea93a 23draw_lock.release()
189bf90c
IB
24
25contexts = [
26 'normal'
27]
28
29context = 'normal'
30
23b7e0e5 31#### Normal workflow ####
189bf90c
IB
32while 1:
33 event = pygame.event.wait()
e7f8dab4 34
189bf90c
IB
35 if event.type == pygame.QUIT or (
36 event.type == pygame.KEYDOWN and
37 event.mod == 4160 and
38 event.key == pygame.K_c):
be27763f 39 for thread in threading.enumerate():
23b7e0e5 40 if thread.getName()[0:2] != "MS":
be27763f
IB
41 continue
42 thread.join()
43
189bf90c
IB
44 pygame.quit()
45 sys.exit()
46
47 if context == 'normal':
d8ab67c7 48 if event.type == pygame.KEYDOWN:
e7f8dab4 49 key = mapping.find_by_key_num(event.key)
fba0caf0 50 if key is not None and not key.disabled:
cd255f24 51 threading.Thread(name = "MSKeyAction", target=key.do_actions, args = [screen]).start()
9de92b6d 52 threading.Thread(name = "MSClic", target=key.list_actions, args = [screen]).start()
d8ab67c7 53 elif event.type == pygame.MOUSEBUTTONUP:
e7f8dab4 54 key = mapping.find_by_collidepoint(pygame.mouse.get_pos())
d8ab67c7 55 if key is not None:
23b7e0e5 56 threading.Thread(name = "MSClic", target=key.list_actions, args = [screen]).start()
189bf90c 57
ba9ea93a 58 draw_lock.acquire()
956ce6fd
IB
59 police = helpers.font(14)
60 icon_police = helpers.font(14, font = "Symbola")
9de92b6d
IB
61
62 surface = pygame.Surface((208, 250)).convert()
63 surface.fill((250, 250, 250))
64 offset = 0
65 for music_file in open_files.values():
66 police.set_bold(False)
67 if music_file.is_playing():
9de92b6d
IB
68 if music_file.is_paused():
69 icon = icon_police.render("⏸", True, (0,0,0))
70 else:
fba0caf0 71 icon = icon_police.render("⏵", True, (0,0,0))
9de92b6d
IB
72 police.set_bold(True)
73 text = police.render(music_file.name, True, (0,0,0))
74 surface.blit(icon, (0, offset))
75 surface.blit(text, (20, offset))
76 offset += police.get_linesize()
77 screen.blit(surface, (700, 308))
78
189bf90c 79 pygame.display.flip()
ba9ea93a 80 draw_lock.release()