aboutsummaryrefslogtreecommitdiff
path: root/music_sampler/app.py
diff options
context:
space:
mode:
Diffstat (limited to 'music_sampler/app.py')
-rw-r--r--music_sampler/app.py91
1 files changed, 91 insertions, 0 deletions
diff --git a/music_sampler/app.py b/music_sampler/app.py
new file mode 100644
index 0000000..81c47a7
--- /dev/null
+++ b/music_sampler/app.py
@@ -0,0 +1,91 @@
1from .helpers import parse_args, register_fonts, duration_to_min_sec, path
2
3parse_args()
4
5import kivy
6kivy.require("1.9.1")
7from kivy.app import App
8from kivy.uix.floatlayout import FloatLayout
9from kivy.uix.relativelayout import RelativeLayout
10from kivy.properties import ListProperty, StringProperty
11from kivy.clock import Clock
12from kivy.core.window import Window
13from kivy.lang import Builder
14from .key import Key
15from .mapping import Mapping
16
17register_fonts()
18
19class KeyList(RelativeLayout):
20 keylist = ListProperty([])
21 first_key = StringProperty("")
22 second_key = StringProperty("")
23 third_key = StringProperty("")
24
25 def append(self, value):
26 self.keylist.insert(0, value)
27
28 def on_keylist(self, instance, new_key_list):
29 if len(self.keylist) > 0:
30 self.first_key = self.keylist[0]
31 if len(self.keylist) > 1:
32 self.second_key = self.keylist[1]
33 if len(self.keylist) > 2:
34 self.third_key = self.keylist[2]
35
36class PlayList(RelativeLayout):
37 playlist = ListProperty([])
38
39 def __init__(self, **kwargs):
40 super(PlayList, self).__init__(**kwargs)
41 Clock.schedule_interval(self.update_playlist, 0.5)
42
43 def update_playlist(self, dt):
44 if self.parent is None or 'Mapping' not in self.parent.ids:
45 return True
46
47 open_files = self.parent.ids['Mapping'].open_files
48 self.playlist = []
49 for music_file in open_files.values():
50 if not music_file.is_in_use():
51 continue
52
53 text = "{}/{}".format(
54 duration_to_min_sec(music_file.sound_position),
55 duration_to_min_sec(music_file.sound_duration))
56
57 if music_file.is_loaded_paused():
58 self.playlist.append(["⏸", music_file.name, text, False])
59 else:
60 self.playlist.append(["⏵", music_file.name, text, True])
61
62
63class ActionList(RelativeLayout):
64 action_title = StringProperty("")
65 action_list = ListProperty([])
66
67 def update_list(self, key, action_descriptions):
68 self.action_title = "actions linked to key {}:".format(key.key_sym)
69 self.action_list = []
70
71 for [action, status] in action_descriptions:
72 if status == "done":
73 icon = "✓"
74 elif status == "current":
75 icon = "✅"
76 else:
77 icon = " "
78 self.action_list.append([icon, action])
79
80class Screen(FloatLayout):
81 pass
82
83class MusicSamplerApp(App):
84 def build(self):
85 Window.size = (913, 563)
86
87 return Screen()
88
89def main():
90 Builder.load_file(path() + "/music_sampler.kv")
91 MusicSamplerApp().run()