Usuario
EJECUTAR EJEMPLO

Pregunta
-
hola. pretendo hacer una aplicacion para generar partituras vi un ejemplo para controlar beep() pero no se como ejecutarlo desde un formulario. El ejemplo es el siguiente:
Imports System
Imports System.Threading
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
*** COMO PUEDO EJECUTAR ESTE CODIGO DESDE UN BOTON
End Sub
End Class
' This example demonstrates the Console.Beep(Int32, Int32) method
Class Sample
Public Shared Sub Main()
' Declare the first few notes of the song, "Mary Had A Little Lamb".
Dim Mary As Note() = { _
New Note(Tone.B, Duration.QUARTER), _
New Note(Tone.A, Duration.QUARTER), _
New Note(Tone.GbelowC, Duration.QUARTER), _
New Note(Tone.A, Duration.QUARTER), _
New Note(Tone.B, Duration.QUARTER), _
New Note(Tone.B, Duration.QUARTER), _
New Note(Tone.B, Duration.HALF), _
New Note(Tone.A, Duration.QUARTER), _
New Note(Tone.A, Duration.QUARTER), _
New Note(Tone.A, Duration.HALF), _
New Note(Tone.B, Duration.QUARTER), _
New Note(Tone.D, Duration.QUARTER), _
New Note(Tone.D, Duration.HALF)}
' Play the song
Play(Mary)
End Sub 'Main
' Play the notes in a song.
Protected Shared Sub Play(tune() As Note)
Dim n As Note
For Each n In tune
If n.NoteTone = Tone.REST Then
Thread.Sleep(CInt(n.NoteDuration))
Else
Console.Beep(CInt(n.NoteTone), CInt(n.NoteDuration))
End If
Next n
End Sub 'Play
' Define the frequencies of notes in an octave, as well as
' silence (rest).
Protected Enum Tone
REST = 0
GbelowC = 196
A = 220
Asharp = 233
B = 247
C = 262
Csharp = 277
D = 294
Dsharp = 311
E = 330
F = 349
Fsharp = 370
G = 392
Gsharp = 415
End Enum 'Tone
' Define the duration of a note in units of milliseconds.
Protected Enum Duration
WHOLE = 1600
HALF = WHOLE / 2
QUARTER = HALF / 2
EIGHTH = QUARTER / 2
SIXTEENTH = EIGHTH / 2
End Enum 'Duration
' Define a note as a frequency (tone) and the amount of
' time (duration) the note plays.
Protected Structure Note
Private toneVal As Tone
Private durVal As Duration
' Define a constructor to create a specific note.
Public Sub New(frequency As Tone, time As Duration)
toneVal = frequency
durVal = time
End Sub 'New
' Define properties to return the note's tone and duration.
Public ReadOnly Property NoteTone() As Tone
Get
Return toneVal
End Get
End Property
Public ReadOnly Property NoteDuration() As Duration
Get
Return durVal
End Get
End Property
End Structure 'Note '
'This example produces the following results:
'
'This example plays the first few notes of "Mary Had A Little Lamb"
'through the console speaker.
'
End Class 'Sample
Todas las respuestas
-
Hola:
Simplemente llama a la función Main de Sample:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
*** COMO PUEDO EJECUTAR ESTE CODIGO DESDE UN BOTONSample.Main()
End Sub
Ahora bien, tienes la clase Sample definida con funciones/sub Shared, quizás sería interesante convertirla a una clase más normal :-)
Saludos
- Propuesto como respuesta LG DES jueves, 23 de octubre de 2014 7:12
-
LG DES, te ha dado una respuesta que me parece correcta.
Ahora, no querrías usar el beep para tu programa.
Puedes dejar al hardware de tu pc que sintetice cada nota.
Para ello usas MIDI. Creas un stream de MIDIEVENTos y con midiStreamOut lo ejecutas.
Acá tienes un wrapper en net code.google.com/p/midi-dot-net para las funciones midi* de la multimedia de windows.
Si escribes en VB para net, no deberías poner tu pregunta en vb para win.
Ten en cuenta que necesitas conocer el lenguaje de programación y la herramienta que vas a utilizar. Casi todos pueden escribir un programa para pc... si saben cómo hacerlo.
/dd
- Editado Domingo22 miércoles, 22 de octubre de 2014 11:53
-
Muy agradecido por tu respuesta, es que estoy acostubrado a otros lenguajes distintos bajo msdos y todo esto lo desconozco, pues lo hago por jovi, yo soy carpintero, pero encanta el mundo de la programación. El primer programa de musica lo hice con expctrum, luego otro con Atari y finalmente otro con dbase y dge. Ahora se que me costará pero tengo mucha ilusion. gracias por todo
-
-
Una última pregunta, para ponerme manos a la obra y buscar informacion necesaria. Tengo instalado VS Exprés para escritorio, que no se si es lo mismo que VB Net. Y tampoco se si decirme ahora que voy a empezar por programar en Visual Basic o en C+ . Que me recomiendas?. Muchas gracias