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
|
' SFX Generator
'
' Copyright (C) 2006 Ian Cowburn (ianc@noddybox.co.uk)
'
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 2 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'
' -------------------------------------------------------------------------
'
' $Id$
'
SuperStrict
Import brl.audio
Import brl.audiosample
Import noddybox.mwidget
Import "types.bmx"
Global top:SFXGenApp
Global menu:TMMenu
Global path:String=""
Type SFXGenApp Extends TMWindow
Field env:EnvelopeControl
Field wave:WaveControl
Field sample:SampleControl
Field labels:TList
Field samples:TMSlider
Field wavefreq:TMSlider
Function Init:SFXGenApp()
Local o:SFXGenApp=SFXGenApp(New SFXGenApp.Create("SFX Generator",100,100,785,500,Null, ..
WINDOW_TITLEBAR|..
WINDOW_MENU|..
WINDOW_CLIENTCOORDS|..
WINDOW_HIDDEN|..
WINDOW_ACCEPTFILES))
o.labels=CreateList()
o.labels.AddLast(New TMLabel.Create("Envelope:",5,5,100,15,o))
o.env=EnvelopeControl(New EnvelopeControl.Create(5,20,400,255,o))
o.labels.AddLast(New TMLabel.Create("Wave:",420,5,100,15,o))
o.wave=WaveControl(New WaveControl.Create(420,20,360,255,o))
o.labels.AddLast(New TMLabel.Create("Sample:",5,300,100,15,o))
o.sample=SampleControl(New SampleControl.Create(5,320,775,100,o))
o.samples=New TMSlider.Create(5,280,15,15,o,SLIDER_STEPPER)
o.samples.SetRange(1,100000)
o.NewSFX()
Return o
End Function
Method OnClose()
'closed=Confirm("Really quit?")
closed=True
End Method
Method OnDrop(p:String)
Load(p)
End Method
Method Load:Int(p:String)
Local s:TStream=ReadStream(p)
If Not s
Return False
EndIf
s=BigEndianStream(s)
Local m:String=ReadString(s,MAGIC.length)
If m<>MAGIC
CloseStream(s)
Return False
EndIf
env.FromStream(s)
wave.FromStream(s)
path=p
CloseStream(s)
Text("SFX Generator -- " + p)
Return True
End Method
Method Save:Int(p:String)
Local s:TStream=WriteStream(p)
If Not s
Return False
EndIf
s=BigEndianStream(s)
WriteString(s,MAGIC)
env.ToStream(s)
wave.ToStream(s)
path=p
CloseStream(s)
Text("SFX Generator -- " + p)
Return True
End Method
Method NewSFX()
env.Clear()
wave.Clear()
sample.Clear()
path=""
Text("SFX Generator -- [untitled]")
End Method
Method Generate()
sample.Generate(env.GetPointList(),wave.GetPointList())
End Method
Method Play()
sample.Play()
End Method
End Type
Function MenuCallback(m:TMMenu, p:String, t:Object)
Select p
Case "/file/new"
menu.Enable("/file/save",False)
menu.Enable("/file/savewav",False)
menu.Enable("/sample/play",False)
top.NewSFX()
Case "/file/open"
Local fn:String=RequestFile("Select SFX to open","SFX Files:sfx;All Files:*",False,path$)
If fn.length
If ExtractExt(fn).length=0
fn:+".sfx"
EndIf
If top.Load(fn$)
menu.Enable("/file/save",True)
End If
EndIf
Case "/file/save"
top.Save(path$)
Case "/file/saveas"
Local fn:String=RequestFile("Select SFX to save","SFX Files:sfx;All Files:*",True,path$)
If fn.length
If ExtractExt(fn).length=0
fn:+".sfx"
EndIf
If top.Save(fn$)
menu.Enable("/file/save",True)
End If
EndIf
Case "/file/savewav"
menu.Enable("/file/save",True)
Case "/file/quit"
top.OnClose()
Case "/wave/flat"
top.wave.SetWave(WaveControl.EMPTY)
Case "/wave/sine"
top.wave.SetWave(WaveControl.SINE)
Case "/wave/square"
top.wave.SetWave(WaveControl.SQUARE)
Case "/wave/triangle"
top.wave.SetWave(WaveControl.TRIANGLE)
Case "/wave/saw"
top.wave.SetWave(WaveControl.SAW)
Case "/wave/noise"
top.wave.SetWave(WaveControl.NOISE)
Case "/sample/generate"
top.Generate()
menu.Enable("/sample/play",True)
Case "/sample/play"
top.Play()
Case "/help/about"
Notify("SFX Generator~nCopyright (c) 2006 Ian Cowburn~n~n" ..
+ "This program is distributed in the hope that it will be useful,~n" ..
+ "but WITHOUT ANY WARRANTY; without even the implied warranty of~n" ..
+ "MERCHANTABILITY Or FITNESS For A PARTICULAR PURPOSE. See the~n" ..
+ "GNU General Public License for more details.")
?Debug
Case "/help/break"
DebugStop
?
End Select
End Function
top=SFXGenApp.Init()
menu=New TMMenu.CreateWindowMenu(top)
menu.Set("/file","File")
menu.Set("/file/new","New",MenuCallback)
menu.Set("/file/open","Open",MenuCallback)
menu.Set("/file/save","Save",MenuCallback)
menu.Set("/file/saveas","Save as...",MenuCallback)
menu.Set("/file/savewav","Save sample...",MenuCallback)
menu.Set("/file/quit","Quit",MenuCallback)
menu.Set("/wave","Wave Form")
menu.Set("/wave/flat","Flat",MenuCallback)
menu.Set("/wave/sine","Sine",MenuCallback)
menu.Set("/wave/square","Square",MenuCallback)
menu.Set("/wave/triangle","Triangle",MenuCallback)
menu.Set("/wave/saw","Sawtooth",MenuCallback)
menu.Set("/wave/noise","Noise",MenuCallback)
menu.Set("/sample","Sample")
menu.Set("/sample/generate","Generate",MenuCallback)
menu.Set("/sample/play","Play",MenuCallback)
menu.Set("/help","Help")
menu.Set("/help/about","About",MenuCallback)
?Debug
menu.Set("/help/break","Debug Break",MenuCallback)
?
menu.Enable("/file/save",False)
menu.Enable("/file/savewav",False)
menu.Enable("/sample/play",False)
top.Hidden(False)
MWidgetMainLoop(top)
End
|