generative modeling for Rhino
I'm trying to use the following code to make GH to sing.
I'm implementing it in a slightly diferent way, since I don't want to use it on a form.
Therefore, I don't know how to use this line:
because "Me" is supposed to be the forms handle. I suppose that I need the Handle for either the Rhino window or the GH window. How can I get it?
All the best,
Public Class Form1
Dim DS As Device
Dim wvFormat As WaveFormat
Dim dsBuffer As SecondaryBuffer
Dim dsDesc As BufferDescription
Const SRATE As Integer = 44100
Const DUR As Double = 1
Const FREQ As Double = 500
Dim sbuf(DUR * SRATE) As Short
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' Open DirectSound
DS = New Microsoft.DirectX.DirectSound.Device
' Create a waveform description
wvFormat.FormatTag = WaveFormatTag.Pcm
wvFormat.Channels = 1
wvFormat.SamplesPerSecond = SRATE
wvFormat.BitsPerSample = 16
wvFormat.AverageBytesPerSecond = 2 * SRATE
wvFormat.BlockAlign = 2
dsDesc = New BufferDescription(wvFormat)
dsDesc.BufferBytes = 2 * DUR * SRATE
dsDesc.Flags = 0
' create a buffer
dsBuffer = New SecondaryBuffer(dsDesc, DS)
' create tone
For i As Integer = 0 To DUR * SRATE
sbuf(i) = 10000 * Math.Sin(2 * Math.PI * FREQ * i / SRATE)
' copy to buffer
dsBuffer.Write(0, sbuf, LockFlag.EntireBuffer)
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
You can get at the Grasshopper main window via:
Do make sure it exists before calling any methods on it. It should never disappear unless you use the _GrasshopperUnloadPlugin command.
I used RhinoApp.MainWindowHandle and it seems to be working but I'll remember it...
I managed to get somewhere and so I wanted to share!
Basically it is a VB component that references the DirectSound dll sent in attachment.
It still lacks some control, but it already sings... :D
If anybody knows a bit about how to control it, I have some questions for you ;)