]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blame_incremental - music_sampler.py
Put time duration in playlist
[perso/Immae/Projets/Python/MusicSampler.git] / music_sampler.py
... / ...
CommitLineData
1import kivy
2kivy.require("1.9.1")
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
9from kivy.lang import Builder
10from helpers.key import Key
11from helpers.mapping import Mapping
12import helpers
13
14class KeyList(RelativeLayout):
15 keylist = ListProperty([])
16 first_key = StringProperty("")
17 second_key = StringProperty("")
18 third_key = StringProperty("")
19
20 def append(self, value):
21 self.keylist.insert(0, value)
22
23 def on_keylist(self, instance, new_key_list):
24 if len(self.keylist) > 0:
25 self.first_key = self.keylist[0]
26 if len(self.keylist) > 1:
27 self.second_key = self.keylist[1]
28 if len(self.keylist) > 2:
29 self.third_key = self.keylist[2]
30
31class PlayList(RelativeLayout):
32 playlist = ListProperty([])
33
34 def __init__(self, **kwargs):
35 super(PlayList, self).__init__(**kwargs)
36 Clock.schedule_interval(self.update_playlist, 0.5)
37
38 def update_playlist(self, dt):
39 if self.parent is None or 'Mapping' not in self.parent.ids:
40 return True
41
42 open_files = self.parent.ids['Mapping'].open_files
43 self.playlist = []
44 for music_file in open_files.values():
45 if not music_file.is_playing():
46 continue
47
48 text = "{}/{}".format(
49 helpers.duration_to_min_sec(music_file.sound_position),
50 helpers.duration_to_min_sec(music_file.sound_duration)
51 )
52
53 if music_file.is_paused():
54 self.playlist.append(["⏸", music_file.name, text, False])
55 else:
56 self.playlist.append(["⏵", music_file.name, text, True])
57
58
59class ActionList(RelativeLayout):
60 action_title = StringProperty("")
61 action_list = ListProperty([])
62
63 def update_list(self, key, action_number = 0):
64 self.action_title = "actions linked to key {}:".format(key.key_sym)
65 self.action_list = []
66
67 action_descriptions = [action.description() for action in key.actions]
68
69 for index, description in enumerate(action_descriptions):
70 if index < int(action_number):
71 icon = "✓"
72 elif index + 0.5 == action_number:
73 icon = "✅"
74 else:
75 icon = " "
76
77 self.action_list.append([icon, description])
78
79class Screen(FloatLayout):
80 pass
81
82class MusicSamplerApp(App):
83 def build(self):
84 Window.size = (913, 563)
85
86 return Screen()
87
88if __name__ == '__main__':
89 Builder.load_file(helpers.path() + "/music_sampler.kv")
90 MusicSamplerApp().run()