************************************************** *-- Form: frmmonadamaphone (c:\documents and settings\mgh\desktop\book\code\monadamaphone\monadamaphone.scx) *-- ParentClass: form *-- BaseClass: form *-- Time Stamp: 04/07/10 03:47:10 PM * DEFINE CLASS frmmonadamaphone AS form Top = 0 Left = 0 Height = 781 Width = 1280 DoCreate = .T. Caption = "Monadamaphone" WindowState = 2 BackColor = RGB(255,255,255) lfresh = .T. nseconds = 0 nmousecoords = 0 ndistance = 0 ngain = 0.40 Name = "frmMonadamaphone" nlastx = .F. nlasty = .F. lmousedown = .F. nxstart = .F. nxstop = .F. DIMENSION amousecoords[1] ADD OBJECT spinner1 AS spinner WITH ; Height = 24, ; Increment = 0.01, ; KeyboardHighValue = 1, ; KeyboardLowValue = 0, ; Left = 48, ; SpinnerHighValue = 1.00, ; SpinnerLowValue = 0.00, ; Top = 12, ; Width = 72, ; ControlSource = "thisform.ngain", ; Name = "Spinner1" ADD OBJECT label1 AS label WITH ; BackStyle = 0, ; Caption = "Gain", ; Height = 17, ; Left = 12, ; Top = 17, ; Width = 40, ; Name = "Label1" ADD OBJECT label2 AS label WITH ; AutoSize = .T., ; BackStyle = 0, ; Caption = "Directions: Click and Drag from the Left side of the canvas to the Right Side", ; Height = 17, ; Left = 274, ; Top = 12, ; Width = 411, ; Name = "Label2" ADD OBJECT label3 AS label WITH ; AutoSize = .T., ; BackStyle = 0, ; Caption = "The time that passes while you are dragging the first line is the duration of the sample", ; Height = 17, ; Left = 334, ; Top = 28, ; Width = 470, ; Name = "Label3" PROCEDURE Destroy ! /n7 chuck --kill ENDPROC PROCEDURE Init ! /n7 chuck --loop set safety off ENDPROC PROCEDURE MouseDown LPARAMETERS nButton, nShift, nXCoord, nYCoord * We haven't started something yet if this.lFresh this.nSeconds = seconds() this.nxStart = nXCoord endif this.lMouseDown = .T. this.nlastx = nXCoord this.nlasty = nYCoord this.nmousecoords = 1 dimension this.aMousecoords[1, 2] this.aMousecoords[1, 1] = nXCoord this.aMousecoords[1, 2] = nYCoord ENDPROC PROCEDURE MouseMove LPARAMETERS nButton, nShift, nXCoord, nYCoord local lnI if this.lMouseDown for lnI = .1 to this.nGain step .1 this.Line(this.nlastx + ((lnI * 10) - 1), this.nlasty + ((lnI * 10) - 1), ; nXCoord + ((lnI * 10) - 1), nYCoord + ((lnI * 10) - 1)) endfor this.nlastx = nXCoord this.nlasty = nYCoord this.nmousecoords = this.nmousecoords + 1 dimension this.aMousecoords[this.nmousecoords, 2] this.aMousecoords[this.nmousecoords, 1] = nXCoord this.aMousecoords[this.nmousecoords, 2] = nYCoord endif ENDPROC PROCEDURE MouseUp LPARAMETERS nButton, nShift, nXCoord, nYCoord local lnLeadOff, lnLeadOut this.lMousedown = .F. if this.lFresh lnLeadOff = 0 lnLeadOut = 0 this.lFresh = .F. this.nSeconds = seconds() - this.nSeconds this.nxstop = nXCoord else lnLeadOff = max(this.aMousecoords[1, 1] - this.nxStart, 0) endif * Make the ChucK file local lcText, lnI, lnLastX text to lcText textmerge noshow // make our patch SinOsc s => dac; <<transform(this.nGain)>> => s.gain; while( true ) { endtext if lnLeadOff > 0 text to lcText textmerge noshow additive 0 => s.freq; <<transform(lnLeadOff / (this.nxStop - this.nxStart) * this.nSeconds ) >>::second => now; endtext endif lnLastX = this.nxStart for lnI = 1 to this.nMousecoords if this.aMousecoords[lnI, 1] - lnLastX > 0 text to lcText textmerge noshow additive <<transform(int(this.Height - this.aMousecoords[lnI, 2]))>> => s.freq; <<transform((this.aMousecoords[lnI, 1] - lnLastX) / (this.nxStop - this.nxStart) * this.nSeconds ) >>::second => now; endtext lnLastX = this.aMousecoords[lnI, 1] endif endfor lnLeadOut = max(this.nxStop - this.aMousecoords[this.nMousecoords, 1], 0) if lnLeadOut > 0 text to lcText textmerge noshow additive 0 => s.freq; <<transform(lnLeadOut / (this.nxStop - this.nxStart) * this.nSeconds ) >>::second => now; endtext endif text to lcText textmerge noshow additive } endtext local lcFile, lcRun *lcFile = sys(2015) + '.ck' lcFile = 'test.ck' strtofile(lcText, lcFile) lcRun = "! /n7 chuck + " + lcFile &lcRun ENDPROC ENDDEFINE * *-- EndDefine: frmmonadamaphone **************************************************