Grasshopper

algorithmic modeling for Rhino

 

Dear all,

 

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:

DS.SetCooperativeLevel(Me, CooperativeLevel.Normal)

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,

Ed

 

Imports Microsoft.DirectX.DirectSound
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
DS.SetCooperativeLevel(Me, CooperativeLevel.Normal)
' 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)
Next
' copy to buffer
dsBuffer.Write(0, sbuf, LockFlag.EntireBuffer)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
dsBuffer.Play(0, BufferPlayFlags.Default)
End Sub

End Class

 

 

 

Views: 514

Replies to This Discussion

You can get at the Grasshopper main window via:

 

Grasshopper.GH_InstanceServer.DocumentEditor

 

Do make sure it exists before calling any methods on it. It should never disappear unless you use the _GrasshopperUnloadPlugin command.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hi David,

 

I used RhinoApp.MainWindowHandle and it seems to be working but I'll remember it...

Thanks,

 

Eduardo

 

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 ;)

 

Best regards,

Eduado

Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service