-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
204 lines (171 loc) · 6.28 KB
/
main.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
from Tkinter import *
from ttk import Frame, Button, Style
import tkMessageBox
import tkFileDialog
import signal, os, sys
from mixwaves import MixWaves
from wavefunctions import WaveFunctions
from mixwaves import MixWaves
from modulatewaves import ModulateWaves
from recordwave import RecordWave
from audiofile import AudioFile
names = []
names.append(None)
names.append(None)
names.append(None)
nctr = 0
class WaveOptions(Frame):
def __init__(self, parent):
# Object Vriables
self.name = None
self.ampval = DoubleVar()
self.tscaleval = DoubleVar()
self.tshiftval = DoubleVar()
self.trevval = DoubleVar()
self.isrev = IntVar()
self.ismodul = IntVar()
self.ismix = IntVar()
self.isplaying = 0
self.ispaused = 0
self.pid = None
# Initialize Frame
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
# Select Button
selectbutton = Button(self.parent, text="Select", command = self.ShowBrowser)
selectbutton.pack(anchor=CENTER)
# Amp slider
var = DoubleVar()
ascale = Scale( self.parent, variable = self.ampval, orient=HORIZONTAL ,from_ = 0,to = 5)
ascale.pack(anchor=CENTER)
alabel = Label(self.parent,text = "Amplitude")
alabel.pack()
# Time Shift slider
var = DoubleVar()
tshscale = Scale( self.parent, variable = self.tshiftval, orient=HORIZONTAL,from_ = -1, to = 1, resolution = 0.5 )
tshscale.pack(anchor=CENTER)
tshlabel = Label(self.parent,text = "Time Shift")
tshlabel.pack()
# Time Scaling slider
var = DoubleVar()
tscscale = Scale( self.parent, variable = self.tscaleval, orient=HORIZONTAL,from_ = 0, to = 8, resolution = 0.5 )
tscscale.pack(anchor=CENTER)
tsclabel = Label(self.parent,text = "Time Scaling")
tsclabel.pack()
# Time Reversal Check Button
CheckVar1 = IntVar()
C1 = Checkbutton(self.parent, text = "Time Reversal", variable = self.isrev, \
onvalue = 1, offvalue = 0, height=2, \
width = 20)
C1.pack()
# Modulation Button
CheckVar2 = IntVar()
C2 = Checkbutton(self.parent, text = "Select for Modulation", variable = self.ismodul, \
onvalue = 1, offvalue = 0, height=2, \
width = 20)
C2.pack()
# Mixing Button
CheckVar3 = IntVar()
C3 = Checkbutton(self.parent, text = "Select for Mixing", variable = self.ismix, \
onvalue = 1, offvalue = 0, height=2, \
width = 20)
C3.pack()
# Play Button
playbutton = Button(self.parent, text="Play", command = self.PlayWave)
playbutton.pack(anchor=CENTER)
# Pause Button
pausebutton = Button(self.parent, text="Pause", command = self.PauseWave)
pausebutton.pack(anchor=CENTER)
def ShowBrowser(self):
file = tkFileDialog.askopenfile(parent=self.parent,mode='rb',title='Choose a file')
if file != None:
data = file.read()
print "I got %d bytes from this file." % len(data)
print "and name of file is: %s" % file.name
self.name = file.name
global nctr
names[nctr] = file.name
nctr += 1
file.close()
def PlayWave(self):
# apply wave operations
self.isplaying = 1
if self.ispaused == 1:
os.kill(self.pid, signal.SIGCONT)
self.ispaused = 0
return
wave = WaveFunctions(self.name)
wave.amplify(self.ampval.get())
wave.scale(self.tscaleval.get())
wave.shift(self.tshiftval.get())
if int(self.isrev.get()) == 1:
wave.reverse()
# more operations when added
child_pid = os.fork()
self.pid = child_pid
if child_pid == 0:
self.isplaying = 1
wave.play()
sys.exit(0)
#pid, status = os.waitpid(child_pid, 0)
def PauseWave(self):
if self.isplaying == 1:
os.kill(self.pid, signal.SIGSTOP)
self.ispaused = 1
self.isplaying = 0
def main():
root = Tk() # the main frame for application
root.geometry("600x430+300+300") # Specifications for the main frame
# Wave Objects
frame_a = LabelFrame(root, text='Wave 1', padx=5, pady=5)
frame_a.grid(sticky=E,row = 0, column = 0)
app = WaveOptions(frame_a)
frame_b = LabelFrame(root, text='Wave 2', padx=5, pady=5)
frame_b.grid(sticky=W, row = 0, column = 1)
app2 = WaveOptions(frame_b)
frame_c = LabelFrame(root, text='Wave 3', padx=5, pady=5)
frame_c.grid(sticky=W, row = 0, column = 2)
app3 = WaveOptions(frame_c)
frame_d = LabelFrame(root, text='Modulate and Play', padx=5, pady=5)
frame_d.grid(sticky=E+W, row = 1, column = 0)
Frame(frame_d)
modbutton = Button(frame_d, text="Modulate Play",command = modplay)
modbutton.pack(anchor=CENTER)
frame_e = LabelFrame(root, text='Mix and Play', padx=5, pady=5)
frame_e.grid(sticky=E+W, row = 1, column = 2)
Frame(frame_e)
mixbutton = Button(frame_e, text="Mix Play",command = mixplay)
mixbutton.pack(anchor=CENTER)
frame_f = LabelFrame(root, text='Record and Play', padx=5, pady=5)
frame_f.grid(sticky=E+W, row = 1, column = 1)
Frame(frame_f)
recordbutton = Button(frame_f, text="Record Play",command = recordplay)
recordbutton.pack(anchor=CENTER)
root.mainloop()
def mixplay():
wav = MixWaves(names[0],names[1],names[2])
wav.mix()
wav.write("out.wav")
new = WaveFunctions("out.wav")
child_pid = os.fork()
if child_pid == 0:
new.play()
sys.exit(0)
def modplay():
wav = ModulateWaves(names[0],names[1],names[2])
wav.modulate()
wav.write("out.wav")
new = WaveFunctions("out.wav")
child_pid = os.fork()
if child_pid == 0:
new.play()
sys.exit(0)
def recordplay():
recorder = RecordWave()
recorder.record_to_file('demo.wav')
a = AudioFile("demo.wav")
a.play()
if __name__ == '__main__':
main()