3 // an AudioPad inspired demo
7 Scheduler
setSleepInterval(0.001)
14 d buf := Buffer clone sizeTo(5000000)
15 d encoder := MP3Encoder clone
20 write(total, " raw, ", encoder outBuffer size, " encoded\n")
22 if (buf size > 4000000,
24 s setSampleRate(44100)
27 s setPath("mixtest.mp3")
32 AudioMixer setAudioDevice(d)
35 s1 := Sound clone open(Path with(launchPath, "SampleLoops/drum.wav"))
36 s2 := Sound clone open(Path with(launchPath, "SampleLoops/bass.wav"))
37 s3 := Sound clone open(Path with(launchPath, "SampleLoops/synth.wav"))
38 AudioMixer addSound(s1)
39 AudioMixer addSound(s2)
40 AudioMixer addSound(s3)
45 jitter
:= List clone append(
46 Point clone set(.375, .25),
47 Point clone set(.125, .75),
48 Point clone set(.875, .25),
49 Point clone set(.625, .75)
53 //glColor4d(1, 1, 0, .5/(jitter size
))
54 m
:= thisMessage argAt(0)
63 doFile(Path
with(launchPath
, "Thing.io"))
66 Mix
appendProto(OpenGL)
67 Mix things
:= List clone
68 Mix selectedThings
:= List clone
69 Mix mpos
:= Point clone
70 Mix dpos
:= Point clone
71 Mix lastMouseDownTime
:= Date clone now
73 Mix framesPerSecond
:= 40
75 sansFont12
:= Font clone open(Path
with(launchPath
, "../../IoResources/Library/Fonts/Free/Sans/Bold.ttf")) setPixelSize(17)
76 sansFont24
:= Font clone open(Path
with(launchPath
, "../../IoResources/Library/Fonts/Free/Sans/Bold.ttf")) setPixelSize(38)
78 Mix reshape
:= method(w
, h
,
81 glViewport(0, 0, w
, h
)
82 glMatrixMode(GL_PROJECTION
)
84 gluOrtho2D(0, w
, 0, h
)
85 glMatrixMode(GL_MODELVIEW
)
87 glClearColor(0, 0, 0, 1)
91 Mix display
:= method(
92 glClear(GL_COLOR_BUFFER_BIT
)
94 things
foreach(thing
, thing display
)
99 Mix keyboard
:= method(key
, x
, y
, Nop)
101 Mix updateSpeakers
:= method(
103 t ?
updateLeftSpeaker(leftSpeaker
)
104 t ?
updateRightSpeaker(rightSpeaker
)
108 Mix motion
:= method(x
, y
,
110 dpos
set(x
, y
) -= mpos
112 selectedThings
foreach(t
,
113 //write("moving ", t
uniqueId, "\n")
121 Mix mouse
:= method(button
, state
, x
, y
,
124 //write("mouse ", x
, " ", y
, "\n")
125 selectedThings
foreach(t
, t unselect
)
128 if(t
touchesPoint(dpos
),
129 selectedThings
append(t
)
137 Mix timer
:= method(v
,
139 glutTimerFunc(1000/200, 0)
142 things
foreach(t
, t ?timer
)
143 glutTimerFunc(1000/framesPerSecond
, 1)
152 glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA
)
153 glutInitWindowSize(width
, height
)
155 Mix leftSpeaker pos
set(width
/2 - width
/15, height
*.8)
156 Mix rightSpeaker pos
set(width
/2 + width
/15, height
*.8)
159 glutCreateWindow("Mix")
166 //glutPassiveMotionFunc
170 //glEnable(GL_LINE_SMOOTH
)
171 //glHint(GL_LINE_SMOOTH_HINT
, GL_NICEST
)
172 //glHint(GL_POINT_SMOOTH_HINT
, GL_NICEST
)
175 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
)
177 AudioMixer setSamplesPerBuffer(44100/10)
183 Mix addLoopAt
:= method(path
, x
, y
,
184 loop
:= Loop
clone open(path
)
187 if (lastLoop
, loop
sizeToIntegerMultipleOfLoop(lastLoop
))
190 Mix things
append(loop
)
194 Mix leftSpeaker
:= Speaker
clone setName("L")
195 Mix rightSpeaker
:= Speaker
clone setName("R")
196 Mix things
append(Mix leftSpeaker
, Mix rightSpeaker
)
198 Mix
addLoopAt(Path
with(launchPath
, "Loops/drum.wav"), 200, 75)
199 Mix
addLoopAt(Path
with(launchPath
, "Loops/bass.wav"), 400, 250)
200 Mix
addLoopAt(Path
with(launchPath
, "Loops/synth.wav"), 600, 75)
203 Mix addLoopAt(Path with(launchPath, "Loops/Progeny/keyboards.wav"), 400, 250)
204 Mix addLoopAt(Path with(launchPath, "Loops/Progeny/guitars.wav"), 600, 75)
205 Mix addLoopAt(Path with(launchPath, "Loops/Progeny/beltram.wav"), 700, 75)
206 Mix addLoopAt(Path with(launchPath, "Loops/Progeny/trumpets.wav"), 100, 75)
207 Mix addLoopAt(Path with(launchPath, "Loops/Progeny/bass.wav"), 200, 75)
208 Mix addLoopAt(Path with(launchPath, "Loops/Progeny/MAM Harmony.wav"), 300, 75)
209 Mix addLoopAt(Path with(launchPath, "Loops/Progeny/oz.wav"), 350, 175)