form caption("EQ Curve") size(450, 300), colour(46, 44, 40), pluginId("eqCV") guiMode("queue")
image bounds(75,30,330,180) colour(0, 0, 0, 255)
image bounds(75,30,1,180) widgetArray("eqGraphLines", 29) colour(255, 255, 255, 50)
image bounds(75,30,330,1) widgetArray("eqGraphHLines", 9) colour(255, 255, 255, 50)
gentable bounds (75,30,330,180) tableNumber (1001) outlineThickness(0) channel("EqGraph_1") sampleRange(1, 1000) tableColour(255,0,0,100) outlineThickness(2) tableBackgroundColour(0,0,0,0) tableGridColour(0,0,0,0) zoom(-1)
gentable bounds (75,30,330,180) tableNumber (1002) outlineThickness(0) channel("EqGraph_2") sampleRange(1, 1000) tableColour(255,127,0,100) outlineThickness(2) tableBackgroundColour(0,0,0,0) tableGridColour(0,0,0,0) zoom(-1)
gentable bounds (75,30,330,180) tableNumber (1003) outlineThickness(0) channel("EqGraph_3") sampleRange(1, 1000) tableColour(220,220,0,100) outlineThickness(2) tableBackgroundColour(0,0,0,0) tableGridColour(0,0,0,0) zoom(-1)
gentable bounds (75,30,330,180) tableNumber (1004) outlineThickness(0) channel("EqGraph_4") sampleRange(1, 1000) tableColour(0,255,0,100) outlineThickness(2) tableBackgroundColour(0,0,0,0) tableGridColour(0,0,0,0) zoom(-1)
gentable bounds (75,30,330,180) tableNumber (1005) outlineThickness(0) channel("EqGraph_5") sampleRange(1, 1000) tableColour(80,120,255,100) outlineThickness(2) tableBackgroundColour(0,0,0,0) tableGridColour(0,0,0,0) zoom(-1)
gentable bounds (75,30,330,180) tableNumber (1006) outlineThickness(0) channel("EqGraph_6") sampleRange(1, 1000) tableColour(200,0,255,50) outlineThickness(2) tableBackgroundColour(0,0,0,0) tableGridColour(0,0,0,0) zoom(-1)
gentable bounds (75,30,330,180) tableNumber (1010) outlineThickness(0) channel("table") sampleRange(1, 1000) fill(0) outlineThickness(2) outlineThickness(2) tableColour(255,255,255,255) tableBackgroundColour(0,0,0,0) tableGridColour(0,0,0,0) ampRange(-1, 1, 1010, .001) zoom(-1)
image bounds(75,30,330,180) file("GUI_Rescources/EqBackground.png")
label bounds(75,30,30,8) text("") fontColour(120, 120, 120, 255) colour(0,0,0,0) widgetArray("eqFreqLabels", 10)
label bounds(75,30,30,8) text("") fontColour(120, 120, 120, 255) colour(0,0,0,0) widgetArray("eqAmpLabels", 10)
image bounds(75, 115, 10, 10) colour(255,0,0,150) corners(10) channel("EQband_1")
image bounds(125, 115, 10, 10) colour(255,127,0,150) corners(10) channel("EQband_2")
image bounds(195, 115, 10, 10) colour(220,220,0,150) corners(10) channel("EQband_3")
image bounds(275, 115, 10, 10) colour(0,255,0,150) corners(10) channel("EQband_4")
image bounds(325, 115, 10, 10) colour(80,120,255,150) corners(10) channel("EQband_5")
image bounds(400, 115, 10, 10) colour(127,0,255,150) corners(10) channel("EQband_6")
label bounds(200,100,50,12) text("") channel("eqValues") align("centre") fontColour("white") colour(0,0,0,127)
button bounds(75, 0, 50, 30) text("prev")channel("prev")
button bounds(200, 0, 50, 30) text("next")channel("next")
label bounds(135, 0, 40, 15) channel("number")
-n -d -+rtmidi=NULL -M0 -m0d
; Initialize the global variables.
ksmps = 64
nchnls = 2
0dbfs = 1
gkSlot init 1
gkBandX[] fillarray 0, 75, 150, 220, 300, 350, 400
gkBandY[] fillarray 0, 120, 120, 120, 120, 120, 120
gkQ[] fillarray 0, 1,1,1,1,1,1
gifreqDiv init 97
giEQXPos init 75
giEQWidth init 330
giEQHeight init 90
giEQOdB init 120
gkEqF[][] init 26,7
gkEqQ[][] init 26,7
gkEqG[][] init 26,7
ginitFreqs[] fillarray 0,10,60,400,1800,6000, 24000
giEqGuiFreqs[] fillarray 10,20,30,40,50,60,70,80,90,100,200,300,400,500,600,700,800,900,1000,2000,3000,4000,5000,6000,7000,8000,9000,10000,20000
instr DrawSine
iX = p4
iY = p5
iQ = p6
iB = p7
iGain = (giEQOdB - iY) / giEQHeight * 15
iFreq = pow(10, (iX - giEQXPos)/gifreqDiv + 1)
;prints "\n Drawing EQ-band %d",iB
gkEqG[gkSlot][iB] = iGain
gkEqF[gkSlot][iB] = iFreq
iYtext limit iY, giEQOdB - giEQHeight + 15, giEQOdB + giEQHeight - 45
iXtext limit iX, giEQXPos + 38, giEQXPos + giEQWidth - 70
if(iFreq < 1000)then
SFreq sprintf "%d Hz", iFreq
else
SFreq sprintf "%1.2f kHz", iFreq/1000
endif
if(iB > 1 && iB < 6)then
String sprintf "text(\"%1.1f dB @ %s \") bounds(%d,%d,90,10)", iGain, SFreq, iXtext-45, (iGain>=0)? iYtext-15: iYtext+20
else
String sprintf "text(\"%s \") bounds(%d,%d,60,10)", SFreq, iXtext-30, (iGain>=0)? iYtext-15: iYtext+5
endif
cabbageSet "eqValues", String
iFreqX = (iX - giEQXPos) / giEQWidth * 1000
iGainX = (giEQOdB - iY) / giEQHeight
if(iB > 1 && iB < 6)then
iBtmXL = iFreqX - 1/iQ * 200
iBtmXR = iFreqX + 1/iQ * 200
if(iBtmXL < 0 ) then
iPhase = abs(iBtmXL) *iQ/400
iLen = 1 - abs(iBtmXL) *iQ/400
isine ftgen 1008,0,2048, 32, -1009, iLen, 1, iPhase
itmp ftgen 1000 + iB,0,2048, -18, 1008,iGainX, 0, iBtmXR, 1007,1,iBtmXR+1, 1000
elseif(iBtmXR > 1000) then
iLen = 1 - (iBtmXR - 1000) *iQ/400
isine ftgen 1008,0,2048, 32, -1009, iLen, 1, 0
itmp ftgen 1000 + iB,0,2048, -18, 1007,1,0,iBtmXL-1, 1008,iGainX, iBtmXL, 1000
else
itmp ftgen 1000 + iB,0,2048, -18, 1007,1,0,iBtmXL-1, 1009,iGainX, iBtmXL, iBtmXR, 1007,1,iBtmXR+1, 1000
endif
elseif(iB == 1)then
iCutX = iFreqX + 20
iBtm = iCutX - 250
if(iBtm < 0) then
iPhase = abs(iBtm)/250 * 90
istrgth = (1 - abs(iBtm)/250)
iLen = istrgth * 0.25
isine ftgen 1014,0,2048, 19, iLen, 1, iPhase, -1
itmp ftgen 1000 + iB,0,2048, -18, 1014, istrgth, 0, iCutX, 1007,1,iCutX+1, 1000
else
istrgth = iBtm / 750 * 5 + 1
iCut ftgen 1016,0,2048, 7, -istrgth, 2048, -1
itmp ftgen 1000 + iB,0,2048, -18, 1016,istrgth,0,iBtm-1, 1012,1, iBtm, iCutX, 1007,1,iCutX+1, 1000
endif
elseif(iB == 6)then
iCutX = iFreqX - 20
iBtm = iCutX + 250
iBtmDlt = 750 - iCutX
if(iBtm > 1000) then
iPhase = 90
istrgth = (1 - abs(iBtmDlt)/250)
iLen = istrgth * 0.25
isine ftgen 1014,0,2048, 19, iLen, 1, iPhase, -1
itmp ftgen 1000 + iB,0,2048, -18, 1007,1, 0, iCutX-1, 1014, istrgth,iCutX, 1000
else
istrgth = iBtmDlt / 750 * 5 + 1
iCut ftgen 1016,0,2048, 7, -1, 2048, -istrgth
itmp ftgen 1000 + iB,0,2048, -18, 1007,1,0,iCutX-1, 1013,1, iCutX, iBtm, 1016,istrgth,iBtm+1, 1000
endif
endif
igraph ftgen 1010,0,2048, -32, 1001,1,1,0, 1002,1,1,0, 1003,1,1,0, 1004,1,1,0, 1005,1,1,0, 1006,1,1,0
cabbageSet "table", "tableNumber(1010)"
String sprintf "tableNumber(%d)", iB + 1000
SIdent sprintf "EqGraph_%d", iB
cabbageSet SIdent, String
endin
opcode freqToX, k,k
kFreq xin
kX = giEQXPos + (log10(kFreq)-1) * gifreqDiv
xout kX
endop
opcode gainToY, k,k
kGain xin
kY = giEQOdB - (kGain * giEQHeight / 15)
xout kY
endop
opcode CheckEqClick,kkk,kk
kX, kY xin
kCnt = 1
while kCnt <= 6 do
kBandX freqToX gkEqF[gkSlot][kCnt]
kBandY gainToY gkEqG[gkSlot][kCnt]
if( kX >= kBandX-5 && kX <= kBandX+5 && kY >= kBandY-5 && kY <= kBandY+5 ) then
goto break
endif
kCnt = kCnt + 1
od
kCnt = 0
break:
printks "\nCOUNT: %d",0.1, kCnt
xout kCnt, kBandX, kBandY
endop
instr 1
kLeftClick cabbageGet "MOUSE_DOWN_LEFT"
kRightClick cabbageGet "MOUSE_DOWN_RIGHT"
kMouseX cabbageGet "MOUSE_X"
kMouseY cabbageGet "MOUSE_Y"
kBand init 0
if(changed(kLeftClick) == 1 && kLeftClick == 1)then
kBand, kBandX, kBandY CheckEqClick kMouseX, kMouseY
if(kBand > 0) then
printks "\n EQ Band: %d",0.1,kBand
kBandDrag = 1
kBandDragDeltaX = kBandX - kMouseX
kBandDragDeltaY = kBandY - kMouseY
endif
endif
if(metro(30) == 1 && kBandDrag == 1)then
if(kLeftClick == 1)then
kBandX limit kMouseX + kBandDragDeltaX, giEQXPos + 1, giEQXPos + giEQWidth - 1
if(kBand > 1 && kBand < 6)then
kBandY limit kMouseY + kBandDragDeltaY, giEQOdB - giEQHeight + 1, giEQOdB + giEQHeight - 1
endif
String sprintfk "bounds(%d, %d, 10, 10)", kBandX - 5, kBandY - 5
SIdent sprintfk "EQband_%d", kBand
cabbageSet 1, SIdent, String
gkEqG[gkSlot][kBand] = (giEQOdB - kBandY) / giEQHeight * 15
gkEqF[gkSlot][kBand] = pow(10, (kBandX - giEQXPos)/gifreqDiv + 1)
event "i", "DrawSine" , 0, 0.0008, kBandX, kBandY, gkEqQ[gkSlot][kBand], kBand, gkEqG[gkSlot][kBand], gkEqF[gkSlot][kBand]
else
printks "\ndrag released",0.1
kBandDrag = 0
kBand = 0
endif
endif
if(changed(kRightClick) == 1)then
kBand, kBandX, kBandY CheckEqClick kMouseX, kMouseY
if(kBand > 0) then
printks "\n EQ Band: %d",0.1,kBand
kQDrag = 1
kQDragDeltaX = kBandX - kMouseX
kQDragDeltaY = kMouseY
kDeltaQ = gkEqQ[gkSlot][kBand]
endif
endif
if(metro(30) == 1 && kQDrag == 1)then
if(kRightClick == 1)then
kBandX limit kMouseX + kQDragDeltaX, giEQXPos + 1, giEQXPos + giEQWidth - 1
gkEqQ[gkSlot][kBand] limit (kQDragDeltaY - kMouseY)/40 + kDeltaQ, 0.5, 10
String sprintfk "bounds(%d, %d, 10, 10)", kBandX - 5, kBandY - 5
SIdent sprintfk "EQband_%d", kBand
cabbageSet 1, SIdent, String
gkEqF[gkSlot][kBand] = pow(10, (kBandX - giEQXPos)/gifreqDiv + 1)
event "i", "DrawSine" , 0, 0, kBandX, kBandY, gkEqQ[gkSlot][kBand], kBand, gkEqG[gkSlot][kBand], gkEqF[gkSlot][kBand]
else
printks "\ndrag released",0.1
kQDrag = 0
endif
endif
gkSlot = (changed(chnget:k("next")) == 1 && gkSlot < 9)? gkSlot + 1 : gkSlot // change active index
gkSlot = (changed(chnget:k("prev")) == 1 && gkSlot > 0)? gkSlot - 1 : gkSlot
if(changed(gkSlot) == 1)then
String sprintfk "text(\"%d\")",gkSlot
cabbageSet 1, "number", String
event "i","UpdateEqGraph",0,0.0008
endif
endin
instr initEqData
iEqCurve ftgen 1009, 0, 2048, 7, 0, 2048, 0
iCnt init 0
icurve init 0
ilength init 2048
while iCnt < ilength do
icurve = iCnt / ilength
icurve = sin($M_PI_2 + (6 * iCnt / ilength - 3) * $M_PI / ( 1.26794 + sqrt(abs(6 * iCnt / ilength - 3))))/2 + 0.5
tablew icurve, iCnt, iEqCurve
iCnt = iCnt + 1
od
kCntSlot init 1
while kCntSlot <= 25 do
kCntBand = 1
while kCntBand <= 6 do
gkEqF[kCntSlot][kCntBand] = ginitFreqs[kCntBand]
gkEqQ[kCntSlot][kCntBand] = 1
kCntBand = kCntBand + 1
od
kCntSlot = kCntSlot + 1
od
kCntGrph init 0
kCntLbl init 1
while kCntGrph<29 do
kEqGrphLineX = giEQXPos + (log10(giEqGuiFreqs[kCntGrph])-1) * gifreqDiv // (giEQWidth - 20)
String sprintfk "bounds(%d,%d,1,%d)" , kEqGrphLineX, giEQOdB - giEQHeight, giEQHeight * 2
SIdent sprintfk "eqGraphLines_ident%d", kCntGrph + 1
cabbageSet 1,SIdent, String
if(kCntGrph == 1 || kCntGrph == 4 || kCntGrph == 9 || kCntGrph == 10 || kCntGrph == 13 || kCntGrph == 18 || kCntGrph == 19 || kCntGrph == 22 || kCntGrph == 27 || kCntGrph == 28) then
if(giEqGuiFreqs[kCntGrph] < 1000) then
String sprintfk "text(\"%d\") bounds(%d,%d,30,8)", giEqGuiFreqs[kCntGrph], kEqGrphLineX - 15,giEQOdB + giEQHeight - 10
else
String sprintfk "text(\"%dk\") bounds(%d,%d,30,8)", giEqGuiFreqs[kCntGrph]/1000, kEqGrphLineX - 15,giEQOdB + giEQHeight - 10
endif
SIdent sprintfk "eqFreqLabels_ident%d",kCntLbl
cabbageSet 1,SIdent, String
kCntLbl += 1
endif
kCntGrph += 1
od
kCntGrph = 0
kCntLbl = 12
while kCntGrph<9 do
kYpos = giEQOdB - giEQHeight + (kCntGrph + 1) * giEQHeight * 2 / 10
String sprintfk "bounds(%d,%d,%d,1)" , giEQXPos, kYpos , giEQWidth
SIdent sprintfk "eqGraphHLines_ident%d", kCntGrph + 1
cabbageSet 1,SIdent, String
if(kCntLbl != 0)then
String sprintfk "text(\"%d dB\") bounds(%d,%d,25,8)", kCntLbl, giEQXPos + giEQWidth - 25, kYpos - 4
SIdent sprintfk "eqAmpLabels_ident%d",kCntGrph + 1
cabbageSet 1,SIdent, String
endif
kCntGrph += 1
kCntLbl -= 3
od
event "i","UpdateEqGraph",0,0.0008
endin
instr UpdateEqGraph
kCntBands init 1
while kCntBands <= 6 do
kEqBandX = giEQXPos + (log10(gkEqF[gkSlot][kCntBands])-1) * gifreqDiv
kEqBandY = giEQOdB - (gkEqG[gkSlot][kCntBands] * giEQHeight / 15)
printks "kEqBandY: %d\n",0.1,kEqBandY
event "i", "DrawSine" , 0, 0, kEqBandX, kEqBandY, gkEqQ[gkSlot][kCntBands] , kCntBands
String sprintfk "bounds(%d, %d, 10, 10)", kEqBandX - 5, kEqBandY - 5
SIdent sprintfk "EQband_%d", kCntBands
cabbageSet 1, SIdent, String
kCntBands += 1
od
event "i","ClearEqValue",0.0,0
endin
instr ClearEqValue
String sprintfk "text(\"\") bounds(%d,%d,1,1)", giEQXPos, giEQOdB - giEQHeight
cabbageSet "eqValues", "text(\"\") bounds(100,100,1,1)"
endin
;causes Csound to run for about 7000 years...
f0 z
f 1007 0 2048 7 0 1023 0 // straight line on 0
f 1009 0 2048 19 1 1 270 1 // sine curve
f 1011 0 2048 7 -1 2048 -1 // line on - 1
f 1012 0 1024 19 0.25 1 0 -1 // LowCut
f 1013 0 1024 19 0.25 1 90 -1 // HighCut
f 1015 0 2048 7 -6 2048 -1 // line left of LowCut
f 1016 0 2048 7 -6 2048 -1
f 1010 0 2048 18 1007 1 0 1023
f 1001 0 2048 18 1007 1 0 1023
f 1002 0 2048 18 1007 1 0 1023
f 1003 0 2048 18 1007 1 0 1023
f 1004 0 2048 18 1007 1 0 1023
f 1005 0 2048 18 1007 1 0 1023
f 1006 0 2048 18 1007 1 0 1023
;starts instrument 1 and runs it for a week
i1 0 [60*60*24*7]
i "initEqData" 0 0.0008