-import sys
+import helpers
-if getattr(sys, 'frozen', False):
- os.chdir(sys._MEIPASS)
+helpers.parse_args()
-import pygame
-import pydub
-import helpers
+import kivy
+kivy.require("1.9.1")
+from kivy.app import App
+from kivy.uix.floatlayout import FloatLayout
+from kivy.uix.relativelayout import RelativeLayout
+from kivy.properties import ListProperty, StringProperty
+from kivy.clock import Clock
+from kivy.core.window import Window
+from kivy.lang import Builder
+from helpers.key import Key
+from helpers.mapping import Mapping
+
+class KeyList(RelativeLayout):
+ keylist = ListProperty([])
+ first_key = StringProperty("")
+ second_key = StringProperty("")
+ third_key = StringProperty("")
+
+ def append(self, value):
+ self.keylist.insert(0, value)
+
+ def on_keylist(self, instance, new_key_list):
+ if len(self.keylist) > 0:
+ self.first_key = self.keylist[0]
+ if len(self.keylist) > 1:
+ self.second_key = self.keylist[1]
+ if len(self.keylist) > 2:
+ self.third_key = self.keylist[2]
+
+class PlayList(RelativeLayout):
+ playlist = ListProperty([])
+
+ def __init__(self, **kwargs):
+ super(PlayList, self).__init__(**kwargs)
+ Clock.schedule_interval(self.update_playlist, 0.5)
+
+ def update_playlist(self, dt):
+ if self.parent is None or 'Mapping' not in self.parent.ids:
+ return True
-pygame.mixer.pre_init(frequency = 44100)
-pygame.init()
+ open_files = self.parent.ids['Mapping'].open_files
+ self.playlist = []
+ for music_file in open_files.values():
+ if not music_file.is_playing():
+ continue
-size = width, height = 1024, 600
+ text = "{}/{}".format(
+ helpers.duration_to_min_sec(music_file.sound_position),
+ helpers.duration_to_min_sec(music_file.sound_duration)
+ )
-screen = pygame.display.set_mode(size)
-background = pygame.Surface(screen.get_size())
-background = background.convert()
-background.fill((250, 250, 250))
+ if music_file.is_paused():
+ self.playlist.append(["⏸", music_file.name, text, False])
+ else:
+ self.playlist.append(["⏵", music_file.name, text, True])
-action_surface = pygame.Surface((600, 250)).convert()
-action_surface.fill((0,0,0))
-helpers.parse_config()
-for key_name in helpers.Mapping.KEYS:
- key = helpers.Mapping.KEYS[key_name]
- key.draw(background)
+class ActionList(RelativeLayout):
+ action_title = StringProperty("")
+ action_list = ListProperty([])
-screen.blit(background, (0, 0))
-screen.blit(action_surface, (10, 330))
+ def update_list(self, key, action_number = 0):
+ self.action_title = "actions linked to key {}:".format(key.key_sym)
+ self.action_list = []
-pygame.display.flip()
+ action_descriptions = [action.description() for action in key.actions]
-contexts = [
- 'normal'
-]
+ for index, description in enumerate(action_descriptions):
+ if index < int(action_number):
+ icon = "✓"
+ elif index + 0.5 == action_number:
+ icon = "✅"
+ else:
+ icon = " "
-context = 'normal'
+ self.action_list.append([icon, description])
-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):
- pygame.quit()
- sys.exit()
+class Screen(FloatLayout):
+ pass
- if context == 'normal':
- if event.type == pygame.KEYDOWN:
- key = helpers.Key.find_by_key_num(event.key)
- if key is not None:
- key.do_actions()
- elif event.type == pygame.MOUSEBUTTONUP:
- key = helpers.Key.find_by_collidepoint(pygame.mouse.get_pos())
- if key is not None:
- key.list_actions(action_surface)
+class MusicSamplerApp(App):
+ def build(self):
+ Window.size = (913, 563)
- pygame.display.flip()
+ return Screen()
+if __name__ == '__main__':
+ Builder.load_file(helpers.path() + "/music_sampler.kv")
+ MusicSamplerApp().run()