From 9ec3d17d3fe6ae3f1d1f8fa38f0edcd5197ea048 Mon Sep 17 00:00:00 2001 From: Ian C Date: Fri, 12 Jun 2020 20:08:53 +0000 Subject: Updates to compile with latest BlitzMax --- SFXGen.bmx | 515 +++++++++++++++++++++++++++++++------------------------------ 1 file changed, 258 insertions(+), 257 deletions(-) (limited to 'SFXGen.bmx') diff --git a/SFXGen.bmx b/SFXGen.bmx index c6ca03a..818695a 100644 --- a/SFXGen.bmx +++ b/SFXGen.bmx @@ -1,257 +1,258 @@ -' 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 +' 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 maxgui.drivers + +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:Int() + 'closed=Confirm("Really quit?") + closed=True + End Method + + Method OnDrop:Int(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:Int(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 -- cgit v1.2.3