Making Samples executable. #!/usr/bin/env io and chmod a+x *.io
[io/quag.git] / addons / Flux / samples / Mix / Mix.io
blob86e35dfb74ad85e8db3486d4db43b45b87e180ee
1 #!/usr/bin/env io
3 // an AudioPad inspired demo
4 // Steve Dekorte, 2003
6 debugCollector := 1
7 Scheduler setSleepInterval(0.001)
9 AudioDevice open
12 d := Object clone
13 d total := 0
14 d buf := Buffer clone sizeTo(5000000)
15 d encoder := MP3Encoder clone
16 d write := method(b,
17 //encoder encode(b)
18 total += b size
19 buf appendSeq(b)
20 write(total, " raw, ", encoder outBuffer size, " encoded\n")
21 AudioDevice write(b)
22 if (buf size > 4000000,
23 s := Sound clone
24 s setSampleRate(44100)
25 s setChannels(2)
26 s setBuffer(buf)
27 s setPath("mixtest.mp3")
28 s write
29 exit
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)
41 wait(10)
42 exit
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)
52 jitterDraw := method(
53 //glColor4d(1, 1, 0, .5/(jitter size))
54 m := thisMessage argAt(0)
55 jitter foreach(j,
56 glPushMatrix
57 j glTranslate
58 m doInContext(sender)
59 glPopMatrix
63 doFile(Path with(launchPath, "Thing.io"))
65 Mix := Object clone
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
72 Mix fullScreen := nil
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,
79 self width := w
80 self height := h
81 glViewport(0, 0, w, h)
82 glMatrixMode(GL_PROJECTION)
83 glLoadIdentity
84 gluOrtho2D(0, w, 0, h)
85 glMatrixMode(GL_MODELVIEW)
86 glLoadIdentity
87 glClearColor(0, 0, 0, 1)
88 display
91 Mix display := method(
92 glClear(GL_COLOR_BUFFER_BIT)
93 glLoadIdentity
94 things foreach(thing, thing display)
95 glFlush
96 glutSwapBuffers
99 Mix keyboard := method(key, x, y, Nop)
101 Mix updateSpeakers := method(
102 things foreach(t,
103 t ?updateLeftSpeaker(leftSpeaker)
104 t ?updateRightSpeaker(rightSpeaker)
108 Mix motion := method(x, y,
109 y := height - y
110 dpos set(x, y) -= mpos
112 selectedThings foreach(t,
113 //write("moving ", t uniqueId, "\n")
114 t pos += dpos
116 self updateSpeakers
117 mpos set(x, y)
118 self display
121 Mix mouse := method(button, state, x, y,
122 y := height - y
123 dpos set(x, y)
124 //write("mouse ", x, " ", y, "\n")
125 selectedThings foreach(t, t unselect)
126 selectedThings empty
127 things foreach(t,
128 if(t touchesPoint(dpos),
129 selectedThings append(t)
130 t select
133 mpos set(x, y)
134 self display
137 Mix timer := method(v,
138 if (v == 0) then(
139 glutTimerFunc(1000/200, 0)
140 yield
141 ) else (
142 things foreach(t, t ?timer)
143 glutTimerFunc(1000/framesPerSecond, 1)
144 self display
149 Mix run := method(
150 self width := 800
151 self height := 800
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)
158 glutInit
159 glutCreateWindow("Mix")
160 glutEventTarget(Mix)
161 glutDisplayFunc
162 glutKeyboardFunc
163 glutMotionFunc
164 glutMouseFunc
165 glutReshapeFunc
166 //glutPassiveMotionFunc
167 glutTimerFunc(0, 0)
168 glutTimerFunc(0, 1)
170 //glEnable(GL_LINE_SMOOTH)
171 //glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
172 //glHint(GL_POINT_SMOOTH_HINT, GL_NICEST)
173 //glLineWidth(1)
174 glEnable(GL_BLEND)
175 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
176 self updateSpeakers
177 AudioMixer setSamplesPerBuffer(44100/10)
178 AudioMixer @@start
179 glutMainLoop
182 lastLoop := nil
183 Mix addLoopAt := method(path, x, y,
184 loop := Loop clone open(path)
185 loop pos set(x, y)
187 if (lastLoop, loop sizeToIntegerMultipleOfLoop(lastLoop))
188 lastLoop := loop
189 loop @start
190 Mix things append(loop)
191 return 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)
212 Mix run