]>
git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blob - music_sampler/app.py
1 from .helpers
import parse_args
, register_fonts
, duration_to_min_sec
, path
7 from kivy
.app
import App
8 from kivy
.uix
.floatlayout
import FloatLayout
9 from kivy
.uix
.relativelayout
import RelativeLayout
10 from kivy
.properties
import ListProperty
, StringProperty
11 from kivy
.clock
import Clock
12 from kivy
.core
.window
import Window
13 from kivy
.lang
import Builder
15 from .mapping
import Mapping
19 class KeyList(RelativeLayout
):
20 keylist
= ListProperty([])
21 first_key
= StringProperty("")
22 second_key
= StringProperty("")
23 third_key
= StringProperty("")
25 def append(self
, value
):
26 self
.keylist
.insert(0, value
)
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]
36 class PlayList(RelativeLayout
):
37 playlist
= ListProperty([])
39 def __init__(self
, **kwargs
):
40 super(PlayList
, self
).__init
__(**kwargs
)
41 Clock
.schedule_interval(self
.update_playlist
, 0.5)
43 def update_playlist(self
, dt
):
44 if self
.parent
is None or 'Mapping' not in self
.parent
.ids
:
47 open_files
= self
.parent
.ids
['Mapping'].open_files
49 for music_file
in open_files
.values():
50 if not music_file
.is_in_use():
53 text
= "{}/{}".format(
54 duration_to_min_sec(music_file
.sound_position
),
55 duration_to_min_sec(music_file
.sound_duration
))
57 if music_file
.is_loaded_paused():
58 self
.playlist
.append(["⏸", music_file
.name
, text
, False])
60 self
.playlist
.append(["⏵", music_file
.name
, text
, True])
63 class ActionList(RelativeLayout
):
64 action_title
= StringProperty("")
65 action_list
= ListProperty([])
67 def update_list(self
, key
, action_descriptions
):
68 self
.action_title
= "actions linked to key {}:".format(key
.key_sym
)
71 for [action
, status
] in action_descriptions
:
74 elif status
== "current":
78 self
.action_list
.append([icon
, action
])
80 class Screen(FloatLayout
):
83 class MusicSamplerApp(App
):
85 Window
.size
= (913, 563)
90 Builder
.load_file(path() + "/music_sampler.kv")
91 MusicSamplerApp().run()