/
launchpad_整合初版.py
306 lines (251 loc) · 11.2 KB
/
launchpad_整合初版.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
import os
import tkinter as tk
import tkinter.font as tkFont
import tkinter.filedialog as fdl
from aupyom import Sampler, Sound
from ipywidgets import interact, FloatSlider
from pydub import AudioSegment
from pydub.playback import play
from threading import Thread
# 看你的音檔位置在哪裡,然後指定位置
os.chdir('D://USER//desktop//')
#設定變數名稱,不同種類的音檔就用from_XXX XXX=mp3,WAV,ogg......etc
# song_name = 'Lucid_Dreamer.mp3'
class launchpad(tk.Frame):
def __init__(self):
tk.Frame.__init__(self)
self.grid()
self.createwidgets()
# 多線程
def threaded_run_1(self, event):
t = Thread(target=self.song1_start)
t.daemon = True
t.start()
def threaded_run_1_lowKey(self, event):
t = Thread(target = self.song1_lowKey)
t.daemon = True
t.start()
def threaded_run_1_hiSpd(self, event):
t = Thread(target = self.song1_hiSpd)
t.daemon = True
t.start()
def threaded_run_1_lowSpd(self, event):
t = Thread(target = self.song1_lowSpd)
t.daemon = True
t.start()
def threaded_run_2(self, event):
t = Thread(target=self.song2_start)
t.daemon = True
t.start()
def threaded_run_2_lowKey(self, event):
t = Thread(target = self.song2_lowKey)
t.daemon = True
t.start()
def threaded_run_2_hiSpd(self, event):
t = Thread(target = self.song2_hiSpd)
t.daemon = True
t.start()
def threaded_run_2_lowSpd(self, event):
t = Thread(target = self.song2_lowSpd)
t.daemon = True
t.start()
def threaded_run_3(self, event):
t = Thread(target=self.song3_start)
t.daemon = True
t.start()
def threaded_run_3_lowKey(self, event):
t = Thread(target = self.song3_lowKey)
t.daemon = True
t.start()
def threaded_run_3_hiSpd(self, event):
t = Thread(target = self.song3_hiSpd)
t.daemon = True
t.start()
def threaded_run_3_lowSpd(self, event):
t = Thread(target = self.song3_lowSpd)
t.daemon = True
t.start()
def threaded_run_4(self, event):
t = Thread(target=self.song4_start)
t.daemon = True
t.start()
def threaded_run_4_lowKey(self, event):
t = Thread(target = self.song4_lowKey)
t.daemon = True
t.start()
def threaded_run_4_hiSpd(self, event):
t = Thread(target = self.song4_hiSpd)
t.daemon = True
t.start()
def threaded_run_4_lowSpd(self, event):
t = Thread(target = self.song4_lowSpd)
t.daemon = True
t.start()
# 視窗
def createwidgets(self):
# 字型
f1 = tkFont.Font(size=20, family='Ink Free')
# 四個輸入歌曲按鍵
self.btnnum1 = tk.Button(self, text='choose1', height=1, width=20, command=self.choose_song1, font=f1)
self.btnnum2 = tk.Button(self, text='choose2', height=1, width=10, command=self.choose_song2, font=f1)
self.btnnum3 = tk.Button(self, text='choose3', height=1, width=10, command=self.choose_song3, font=f1)
self.btnnum4 = tk.Button(self, text='choose4', height=1, width=10, command=self.choose_song4, font=f1)
# 升key
self.btnnum1_1 = tk.Button(self, text='', height=1, width=10, command=self.threaded_run_1, font=f1)
self.btnnum2_1 = tk.Button(self, text='', height=1, width=10, command=self.threaded_run_2, font=f1)
self.btnnum3_1 = tk.Button(self, text='', height=1, width=10, command=self.threaded_run_3, font=f1)
self.btnnum4_1 = tk.Button(self, text='', height=1, width=10, command=self.threaded_run_4, font=f1)
# 降key
self.btnnum1_lowKey = tk.Button(self, text='', height=1, width=10, command=self.threaded_run_1_lowKey, font=f1)
self.btnnum2_lowKey = tk.Button(self, text='', height=1, width=10, command=self.threaded_run_2_lowKey, font=f1)
self.btnnum3_lowKey = tk.Button(self, text='', height=1, width=10, command=self.threaded_run_3_lowKey, font=f1)
self.btnnum4_lowKey = tk.Button(self, text='', height=1, width=10, command=self.threaded_run_4_lowKey, font=f1)
# 升速
self.btnnum1_hiSpd = tk.Button(self, text='', height=1, width=10, command=self.threaded_run_1_hiSpd, font=f1)
self.btnnum2_hiSpd = tk.Button(self, text='', height=1, width=10, command=self.threaded_run_2_hiSpd, font=f1)
self.btnnum3_hiSpd = tk.Button(self, text='', height=1, width=10, command=self.threaded_run_3_hiSpd, font=f1)
self.btnnum4_hiSpd = tk.Button(self, text='', height=1, width=10, command=self.threaded_run_4_hiSpd, font=f1)
#降速
self.btnnum1_lowSpd = tk.Button(self, text='', height=1, width=10, command=self.threaded_run_1_lowSpd, font=f1)
self.btnnum2_lowSpd = tk.Button(self, text='', height=1, width=10, command=self.threaded_run_2_lowSpd, font=f1)
self.btnnum3_lowSpd = tk.Button(self, text='', height=1, width=10, command=self.threaded_run_3_lowSpd, font=f1)
self.btnnum4_lowSpd = tk.Button(self, text='', height=1, width=10, command=self.threaded_run_4_lowSpd, font=f1)
# 按鍵排版
self.btnnum1.grid(row=0, column=0, sticky=tk.NE + tk.SW)
self.btnnum2.grid(row=1, column=0, sticky=tk.NE + tk.SW)
self.btnnum3.grid(row=2, column=0, sticky=tk.NE + tk.SW)
self.btnnum4.grid(row=3, column=0, sticky=tk.NE + tk.SW)
self.btnnum1_1.grid(row=0, column=1, sticky=tk.NE + tk.SW)
self.btnnum2_1.grid(row=1, column=1, sticky=tk.NE + tk.SW)
self.btnnum3_1.grid(row=2, column=1, sticky=tk.NE + tk.SW)
self.btnnum4_1.grid(row=3, column=1, sticky=tk.NE + tk.SW)
self.btnnum1_lowKey.grid(row=0, column=2, sticky=tk.NE + tk.SW)
self.btnnum2_lowKey.grid(row=1, column=2, sticky=tk.NE + tk.SW)
self.btnnum3_lowKey.grid(row=2, column=2, sticky=tk.NE + tk.SW)
self.btnnum4_lowKey.grid(row=3, column=2, sticky=tk.NE + tk.SW)
self.btnnum1_hiSpd.grid(row=0, column=3, sticky=tk.NE + tk.SW)
self.btnnum2_hiSpd.grid(row=1, column=3, sticky=tk.NE + tk.SW)
self.btnnum3_hiSpd.grid(row=2, column=3, sticky=tk.NE + tk.SW)
self.btnnum4_hiSpd.grid(row=3, column=3, sticky=tk.NE + tk.SW)
self.btnnum1_lowSpd.grid(row=0, column=4, sticky=tk.NE + tk.SW)
self.btnnum2_lowSpd.grid(row=1, column=4, sticky=tk.NE + tk.SW)
self.btnnum3_lowSpd.grid(row=2, column=4, sticky=tk.NE + tk.SW)
self.btnnum4_lowSpd.grid(row=3, column=4, sticky=tk.NE + tk.SW)
# 鍵盤操作
self.btnnum1_1.bind_all('1', self.threaded_run_1)
self.btnnum2_1.bind_all('q', self.threaded_run_2)
self.btnnum3_1.bind_all('a', self.threaded_run_3)
self.btnnum4_1.bind_all('z', self.threaded_run_4)
self.btnnum1_lowKey.bind_all('2', self.threaded_run_1_lowKey)
self.btnnum2_lowKey.bind_all('w', self.threaded_run_2_lowKey)
self.btnnum3_lowKey.bind_all('s', self.threaded_run_3_lowKey)
self.btnnum4_lowKey.bind_all('x', self.threaded_run_4_lowKey)
self.btnnum1_lowKey.bind_all('3', self.threaded_run_1_hiSpd)
self.btnnum2_lowKey.bind_all('e', self.threaded_run_2_hiSpd)
self.btnnum3_lowKey.bind_all('d', self.threaded_run_3_hiSpd)
self.btnnum4_lowKey.bind_all('c', self.threaded_run_4_hiSpd)
self.btnnum1_lowKey.bind_all('4', self.threaded_run_1_lowSpd)
self.btnnum2_lowKey.bind_all('r', self.threaded_run_2_lowSpd)
self.btnnum3_lowKey.bind_all('f', self.threaded_run_3_lowSpd)
self.btnnum4_lowKey.bind_all('v', self.threaded_run_4_lowSpd)
def choose_song1(self):
default_dir = r'D:\\college\\107-1\\商管程式設計\\Final_Project' # 设置默认打开目录
global song_name1
song_name1 = fdl.askopenfilename(title=u"选择文件", initialdir=(os.path.expanduser(default_dir)))
def choose_song2(self):
default_dir = r'D:\\college\\107-1\\商管程式設計\\Final_Project' # 设置默认打开目录
global song_name2
song_name2 = fdl.askopenfilename(title=u"选择文件", initialdir=(os.path.expanduser(default_dir)))
def choose_song3(self):
default_dir = r'D:\\college\\107-1\\商管程式設計\\Final_Project' # 设置默认打开目录
global song_name3
song_name3 = fdl.askopenfilename(title=u"选择文件", initialdir=(os.path.expanduser(default_dir)))
def choose_song4(self):
default_dir = r'D:\\college\\107-1\\商管程式設計\\Final_Project' # 设置默认打开目录
global song_name4
song_name4 = fdl.askopenfilename(title=u"选择文件", initialdir=(os.path.expanduser(default_dir)))
# 音訊處理功能
def song1_start(self):
sampler = Sampler()
s1 = Sound.from_file(song_name1)
s1.pitch_shift = 1
sampler.play(s1)
def song1_lowKey(self):
sampler = Sampler()
s1 = Sound.from_file(song_name1)
s1.pitch_shift = -1
sampler.play(s1)
def song1_hiSpd(self):
sampler = Sampler()
s1 = Sound.from_file(song_name1)
s1.stretch_factor = 2
sampler.play(s1)
def song1_lowSpd(self):
sampler = Sampler()
s1 = Sound.from_file(song_name1)
s1.stretch_factor = 0.5
sampler.play(s1)
def song2_start(self):
sampler = Sampler()
s2 = Sound.from_file(song_name2)
s2.pitch_shift = 1
sampler.play(s2)
def song2_lowKey(self):
sampler = Sampler()
s2 = Sound.from_file(song_name2)
s2.pitch_shift = -1
sampler.play(s2)
def song2_hiSpd(self):
sampler = Sampler()
s2 = Sound.from_file(song_name2)
s2.stretch_factor = 2
sampler.play(s2)
def song2_lowSpd(self):
sampler = Sampler()
s2 = Sound.from_file(song_name2)
s2.stretch_factor = 0.5
sampler.play(s2)
def song3_start(self):
sampler = Sampler()
s3 = Sound.from_file(song_name3)
s3.pitch_shift = 1
sampler.play(s3)
def song3_lowKey(self):
sampler = Sampler()
s3 = Sound.from_file(song_name3)
s3.pitch_shift = -1
sampler.play(s3)
def song3_hiSpd(self):
sampler = Sampler()
s3 = Sound.from_file(song_name3)
s3.stretch_factor = 2
sampler.play(s3)
def song3_lowSpd(self):
sampler = Sampler()
s3 = Sound.from_file(song_name3)
s3.stretch_factor = 0.5
sampler.play(s3)
def song4_start(self):
sampler = Sampler()
s4 = Sound.from_file(song_name4)
s4.pitch_shift = 1
sampler.play(s4)
def song4_lowKey(self):
sampler = Sampler()
s4 = Sound.from_file(song_name4)
s4.pitch_shift = -1
sampler.play(s4)
def song4_hiSpd(self):
sampler = Sampler()
s4 = Sound.from_file(song_name4)
s4.stretch_factor = 2
sampler.play(s4)
def song1_lowSpd(self):
sampler = Sampler()
s4 = Sound.from_file(song_name4)
s4.stretch_factor = 0.5
sampler.play(s4)
# 運作
window = launchpad()
window.master.title('launchpad')
window.mainloop()