]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blame - music_sampler.py
Don't run not enabled keys
[perso/Immae/Projets/Python/MusicSampler.git] / music_sampler.py
CommitLineData
d8046b94
IB
1import kivy
2kivy.require("1.9.1")
4b2d79ca
IB
3from kivy.app import App
4from kivy.uix.floatlayout import FloatLayout
5from kivy.uix.relativelayout import RelativeLayout
6from kivy.properties import ListProperty, StringProperty
7from kivy.clock import Clock
8from kivy.core.window import Window
bb69f62e 9from kivy.lang import Builder
4b2d79ca
IB
10from helpers.key import Key
11from helpers.mapping import Mapping
12
bb69f62e
IB
13import sys
14
15if getattr(sys, 'frozen', False):
16 Builder.load_file(sys._MEIPASS + '/musicsampler.kv')
17
4b2d79ca
IB
18class PlayList(RelativeLayout):
19 playlist = ListProperty([])
20
21 def __init__(self, **kwargs):
22 super(PlayList, self).__init__(**kwargs)
23 Clock.schedule_interval(self.update_playlist, 0.5)
24
25 def update_playlist(self, dt):
26 if self.parent is None or 'Mapping' not in self.parent.ids:
27 return True
28
29 open_files = self.parent.ids['Mapping'].open_files
30 self.playlist = []
31 for music_file in open_files.values():
32 if not music_file.is_playing():
33 continue
34 if music_file.is_paused():
35 self.playlist.append(["⏸", music_file.name, False])
36 else:
37 self.playlist.append(["⏵", music_file.name, True])
189bf90c 38
189bf90c 39
4b2d79ca
IB
40class ActionList(RelativeLayout):
41 action_title = StringProperty("")
42 action_list = ListProperty([])
189bf90c 43
4b2d79ca
IB
44 def update_list(self, key, action_number = 0):
45 self.action_title = "actions linked to key {}:".format(key.key_sym)
46 self.action_list = []
189bf90c 47
4b2d79ca 48 action_descriptions = [action.description() for action in key.actions]
e7f8dab4 49
4b2d79ca
IB
50 for index, description in enumerate(action_descriptions):
51 if index < int(action_number):
52 icon = "✓"
53 elif index + 0.5 == action_number:
54 icon = "✅"
55 else:
56 icon = " "
be27763f 57
4b2d79ca 58 self.action_list.append([icon, description])
189bf90c 59
4b2d79ca
IB
60class Screen(FloatLayout):
61 pass
189bf90c 62
4b2d79ca
IB
63class MusicSamplerApp(App):
64 def build(self):
65 Window.size = (913, 563)
9de92b6d 66
4b2d79ca 67 return Screen()
9de92b6d 68
4b2d79ca
IB
69if __name__ == '__main__':
70 MusicSamplerApp().run()