File tree Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -127,15 +127,13 @@ def play_sample(sample:dict) -> None:
127
127
i = get_sample_index (sample ["name" ])
128
128
wav = samples [sample ["name" ]]
129
129
mixer .voice [i ].level = sample .get ("level" , LEVEL )
130
+ mixer .voice [i ].loop = sample .get ("loop" , False )
130
131
mixer .voice [i ].play (wav )
131
132
132
- def stop_sample (name :str ) -> None :
133
- global samples
134
- if name in samples :
135
- for i , val in enumerate (samples .keys ()):
136
- if val == name :
137
- mixer .voice [i ].stop ()
138
- break
133
+ def stop_sample (sample :dict ) -> None :
134
+ if sample .get ("loop" , False ):
135
+ i = get_sample_index (sample ["name" ])
136
+ mixer .voice [i ].stop ()
139
137
140
138
# Keyboard
141
139
@@ -146,8 +144,7 @@ async def touch_handler():
146
144
if event .pressed :
147
145
play_sample (sample )
148
146
elif event .released :
149
- pass
150
- # stop_sample(name)
147
+ stop_sample (sample )
151
148
await asyncio .sleep (0.005 )
152
149
153
150
# MIDI
@@ -163,8 +160,7 @@ async def midi_handler():
163
160
if isinstance (msg , NoteOn ) and msg .velocity != 0 :
164
161
play_sample (sample )
165
162
elif isinstance (msg , NoteOff ) or (isinstance (msg , NoteOn ) and msg .velocity == 0 ):
166
- pass
167
- # stop_sample(name)
163
+ stop_sample (sample )
168
164
await asyncio .sleep (0 )
169
165
170
166
# Controls
You can’t perform that action at this time.
0 commit comments