]>
git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blob - helpers/music_file.py
6 def __init__(self
, filename
, lock
):
7 self
.filename
= filename
13 threading
.Thread(name
= "MSMusicLoad", target
= self
.load_sound
, args
= [lock
]).start()
15 def load_sound(self
, lock
):
17 print("Loading {}".format(self
.filename
))
18 self
.raw_data
= pydub
.AudioSegment
.from_file(self
.filename
).raw_data
19 self
.sound
= pygame
.mixer
.Sound(self
.raw_data
)
20 print("Loaded {}".format(self
.filename
))
25 return self
.channel
is not None and self
.channel
.get_busy()
27 def play(self
, fade_in
= 0, volume
= 100, start_at
= 0):
28 self
.set_volume(volume
)
31 song_duration
= self
.sound
.get_length()
32 raw_data_length
= len(self
.raw_data
)
33 start_offset
= int((raw_data_length
/ song_duration
) * start_at
)
34 start_offset
= start_offset
- (start_offset
% 2)
35 self
.sound
= pygame
.mixer
.Sound(self
.raw_data
[start_offset
:])
37 self
.sound
= pygame
.mixer
.Sound(self
.raw_data
)
39 self
.channel
= self
.sound
.play(fade_ms
= fade_in
* 1000)
42 if self
.channel
is not None:
45 def stop(self
, fade_out
= 0):
48 self
.sound
.fadeout(fade_out
* 1000)
52 def set_volume(self
, value
):
57 self
.sound
.set_volume(value
/ 100)