For those of you who know what this is, yeah I stole the editing layout concept from a VSTi called sytrus. The log mapping mode just makes it easier to make small changes in harmonic amplitudes.
Code: Select all
'Editables!
Const ScreenX as integer = 768
Const ScreenY as integer = 500
Const Harmonics as integer = 32
Const VEWidth as integer = 768
Const ViewHeight as integer = 200
Const EditHeight as integer = 300
'Dont edit these!
Const ViewHeight8 as double = ViewHeight/8
Const ViewWidth32 as double = VEWidth/32
Const VEHeight as integer = ViewHeight+EditHeight
Const BEST_FIT as integer = 0
Const TRUNCATE as integer = 1
Const MAX_FIT as integer = 2
Dim shared as integer WindowingMode
Const HarWidth as double = VEWidth / Harmonics
Const OffYPos as integer = ViewHeight + (EditHeight/2)
Const WaveYMP as integer = ViewHeight/2
Const EditYMP as integer = EditHeight/2-1
Const RecEY as double = 1/EditYMP
Const RecW as double = 1/VEWidth
Const LOGARITHMIC_MAP AS integer = 1
Const LINEAR_MAP As integer = 2
Dim shared as integer MappingMode
Type HarmonicType
as double Amplitude ,_
Offset ,_
CycleMul
End Type
Dim shared as double Sample(1 to VEWidth)
Dim shared as HarmonicType Harmonic(1 to Harmonics)
Dim as integer i
For i = 1 to Harmonics
Harmonic(i).CycleMul = i*2
Next i
Dim shared as uinteger OScopeColors(1 to 7)
OScopeColors(1) = RGB(00,60,00)
OScopeColors(2) = RGB(00,100,00)
OScopeColors(3) = OScopeColors(1)
OScopeColors(4) = RGB(64,100,64)
OScopeColors(5) = OScopeColors(1)
OScopeColors(6) = OScopeColors(2)
OScopeColors(7) = OScopeColors(1)
Sub DrawView()
Dim as integer i, PRE, sm1, sm2
Line (0,0)-(VEWidth-1,ViewHeight-1), RGB(00,25,0), BF
For i = 1 to 31
PRE = i*ViewWidth32-1
Line (PRE,0)-(PRE,ViewHeight-1), RGB(00,35,00)
Next i
For i = 1 to 7
PRE = i*ViewHeight8-1
Line (0,PRE)-(VEWidth-1,PRE), OScopeColors(i)
Next i
sm2 = Sample(i)*WaveYMP + WaveYMP - 1
If sm2 < 0 Then sm2 = 0
For i = 1 to VEWidth-1
sm1 = sm2
sm2 = Sample(i+1)*WaveYMP + WaveYMP - 1
If sm2 < 0 Then sm2 = 0
Line (i-1,sm1)-(i,sm2), &HFFFFFF
Next i
End Sub
Sub DrawEdit()
Dim as integer i, PRE, PRE2, EHeight
Line (0,ViewHeight)-(VEWidth-1,VEHeight-1), RGB(128,128,128), B
Line (0,OffYPos)-(VEWidth-1,OffYPos), RGB(128,128,128)
For i = 1 to Harmonics-1
PRE = i * HarWidth
Line (PRE, ViewHeight)-(PRE,VEHeight-1), RGB(128,128,128)
Next i
For i = 1 to Harmonics
PRE = (i-1)*HarWidth+1
PRE2 = PRE+HarWidth-2
With Harmonic(i)
If .Amplitude>0 Then
EHeight = OffYPos-.Amplitude*EditYMP
Line (PRE,EHeight)-(PRE2,OffYPos-1), RGB(255,128,128), BF
Endif
If .Offset>0 Then
EHeight = OffYPos+.Offset*EditYMP
Line (PRE,OffYPos+1)-(PRE2,EHeight), RGB(128,64,64), BF
Endif
End With
Next i
End Sub
Function Sqw(x as double) as double
Dim as integer xi
xi = int(abs(x))+1
Return (xi mod 2) * 2 - 1
End function
Sub AddHarmonics()
Dim as integer i, Smp
Dim as double wpos, largest, diff
If MappingMode = LOGARITHMIC_MAP Then
For Smp = 1 to VEWidth
Sample(Smp) = 0
For i = 1 to Harmonics
With Harmonic(i)
If .Amplitude > 0 Then
Sample(Smp) += (Sqw(((.Offset*2/.CycleMul)+wpos)*.CycleMul)*(0.1^(1-.Amplitude))*.Amplitude)
Endif
End With
Next i
wpos += RecW
Next Smp
Else
For Smp = 1 to VEWidth
Sample(Smp) = 0
For i = 1 to Harmonics
With Harmonic(i)
If .Amplitude > 0 Then
Sample(Smp) += Sqw(((.Offset*2/.CycleMul)+wpos)*.CycleMul)*.Amplitude
Endif
End With
Next i
wpos += RecW
Next Smp
Endif
Select Case WindowingMode
Case TRUNCATE
For Smp = 1 to VEWidth
If Sample(Smp) > 1 Then
Sample(Smp) = 1
Elseif Sample(Smp) < -1 Then
Sample(Smp) = -1
Endif
Next SMP
Case BEST_FIT
For Smp = 1 to VEWidth
If Abs(Sample(Smp)) > largest Then largest = Abs(Sample(Smp))
Next Smp
diff = 1/largest
For Smp = 1 to VEWidth
If Abs(Sample(Smp)) > 0 Then Sample(Smp) *= diff
Next Smp
Case MAX_FIT
For Smp = 1 to VEWidth
If Abs(Sample(Smp)) > largest Then largest = Abs(Sample(Smp))
Next Smp
If largest > 1 Then
diff = 1/largest
For Smp = 1 to VEWidth
Sample(Smp) *= diff
Next Smp
Endif
End Select
End Sub
Dim as integer mx, my, mb
Dim as integer CWindow
Dim as double CurHar, Amnt
Screenres ScreenX,ScreenY,32,2,8
screenset 1,0
Print "Use the mouse to modify the harmonic"
Print "Amplitude and Offset by clicking in "
Print "either the top or bottom row of collums."
Print "Top = Amplitude, Bottom = Offset"
Print
Print
Print "Windowing mode keyboard settings:"
Print "1 = Truncate"
Print "2 = Fit only maximum"
Print "3 = Fit to maximum"
Print
Print "Amplitude mapping mode keyboard settings:"
Print "Q = Linear"
Print "W = Logarithmic"
Print
Print
Print "Press any key to continue..."
Flip
sleep
WindowingMode = MAX_FIT
MappingMode = LOGARITHMIC_MAP
Do
Cls
getmouse mx, my,,mb
If Multikey(&H2) Then
WindowingMode = TRUNCATE
ElseIf Multikey(&H3) Then
WindowingMode = MAX_FIT
ElseIf Multikey(&H4) Then
WindowingMode = BEST_FIT
Endif
If Multikey(&H10) Then
MappingMode = LINEAR_MAP
Elseif Multikey(&H11) Then
MappingMode = LOGARITHMIC_MAP
Endif
If mb > 0 Then
If CWindow = 0 Then
If my > ViewHeight Then
If my < OffYPos Then
CWindow = 1
Else
CWindow = 2
Endif
Endif
Endif
If CWindow = 1 Then
CurHar = int(mx/HarWidth)+1
Amnt = (OffYPos-my)
If CurHar < 1 Then
CurHar = 1
Elseif CurHar > Harmonics Then
CurHar = Harmonics
Endif
If Amnt > EditYMP Then
Amnt = EditYMP
Elseif Amnt < 0 Then
Amnt = 0
Endif
Amnt *= RecEY
Harmonic(CurHar).Amplitude = Amnt
Elseif CWindow = 2 Then
CurHar = int(mx/HarWidth)+1
Amnt = (my-OffYPos)
If CurHar < 1 Then
CurHar = 1
Elseif CurHar > Harmonics Then
CurHar = Harmonics
Endif
If Amnt > EditYMP Then
Amnt = EditYMP
Elseif Amnt < 0 Then
Amnt = 0
Endif
Amnt *= RecEY
Harmonic(CurHar).Offset = Amnt
Endif
Elseif mb <> -1 Then
CWindow = 0
Endif
AddHarmonics
DrawView
DrawEdit
Flip
Loop until multikey(1)
end