none
MIDI Input! RRS feed

  • Discussão Geral

  • Olá...estou tentando fazer um pequeno piano em VB 2015...

    Quero controlar o piano com o meu controlador MIDI! Já tenho este codigo que me permite escolher o controlador MIDI e tocar!

    No entanto quando primo o tecla do controlador ..o som toca ..mas quando tiro o dedo da tecla o som toca outra vez!

    As notas também parecem ser infinitas...algumas ficam a tocar infinitamente!

    Alguém me ajude?

    Aqui está o codigo que tenho por agora:

    estou usando um modulo chamado clsMIDI...

    Public Class Form1
        Dim m As New clsMIDI
        Dim hMidiIn As Integer
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            If midiInGetNumDevs() = 0 Then
                MsgBox("No MIDI devices connected")
            End If
    
            Dim InCaps As New MIDIINCAPS
            Dim DevCnt As Integer
    
            For DevCnt = 0 To (midiInGetNumDevs - 1)
                midiInGetDevCaps(DevCnt, InCaps, Len(InCaps))
                ComboBox1.Items.Add(InCaps.szPname)
            Next DevCnt
    
            midiInStart(hMidiIn)
        End Sub
    
        Private Sub Form1_Closed(sender As Object, e As EventArgs) Handles Me.Closed
            midiInStop(hMidiIn)
            midiInReset(hMidiIn)
            midiInClose(hMidiIn)
        End Sub
    
        Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
            Dim DeviceID As Integer = ComboBox1.SelectedIndex
            midiInOpen(hMidiIn, DeviceID, AddressOf MidiInProc, 0, CALLBACK_FUNCTION)
            midiInStart(hMidiIn)
        End Sub
    
        Function MidiInProc(ByVal hMidiIn As Integer, ByVal wMsg As UInteger, ByVal dwInstance As Integer, ByVal dwParam1 As Integer, ByVal dwParam2 As Integer) As Integer
            Dim DataByte1 = (dwParam1 And &HFF00) >> 8
            m.PlayMIDINote(DataByte1, 127)
        End Function
    
    
    End Class

    Obrigado!

    sexta-feira, 24 de novembro de 2017 17:05

Todas as Respostas

  • E então?! ... ninguém tem informação acerca disto que me possa ajudar?
    domingo, 26 de novembro de 2017 12:52
  • Pah..eu mudei o meu codigo e ao que parece consigo tocar...falta-me é aqui a cena do "noteduration"..diz que está a utilizar um thread para o qual não foi criado!!

    Alguém me ajuda ou não?

    Public Class Form1
        Dim m As New clsMIDI
        Dim hMidiIn As Integer
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            FillInstrumentCombo()
    
            If midiInGetNumDevs() = 0 Then
                MsgBox("No MIDI devices connected")
            End If
    
            Dim InCaps As New MIDIINCAPS
            Dim DevCnt As Integer
    
            For DevCnt = 0 To (midiInGetNumDevs - 1)
                midiInGetDevCaps(DevCnt, InCaps, Len(InCaps))
                ComboBox1.Items.Add(InCaps.szPname)
            Next DevCnt
    
            midiInStart(hMidiIn)
        End Sub
    
        Private Sub Form1_Closed(sender As Object, e As EventArgs) Handles Me.Closed
            midiInStop(hMidiIn)
            midiInReset(hMidiIn)
            midiInClose(hMidiIn)
        End Sub
    
        Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
            Dim DeviceID As Integer = ComboBox1.SelectedIndex
            midiInOpen(hMidiIn, DeviceID, AddressOf MidiInProc, 0, CALLBACK_FUNCTION)
            midiInStart(hMidiIn)
        End Sub
    
        Private Sub FillInstrumentCombo()
            For i = 0 To 128
                cboInstruments.Items.Add(Instrument.GMInstrumentNames(i))
            Next
            cboInstruments.SelectedIndex = 0
        End Sub
    
        Private Sub cboInstruments_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboInstruments.SelectedIndexChanged
            m.CurrentInstrument = cboInstruments.Text
        End Sub
    
        Private Sub hsbVolume_ValueChanged(sender As Object, e As EventArgs) Handles hsbVolume.ValueChanged
            m.Volume = hsbVolume.Value
        End Sub
    
        Function MidiInProc(ByVal hMidiIn As Integer, ByVal wMsg As UInteger, ByVal dwInstance As Integer, ByVal dwParam1 As Integer, ByVal dwParam2 As Integer) As Integer
            Dim DataByte1 = (dwParam1) >> 8
            m.PlayMIDINote(DataByte1, 127)
            m.NoteDuration = CInt(cboduration.Text)
            m.Pan = 50
        End Function
    
    End Class

    Obrigado

    quarta-feira, 29 de novembro de 2017 14:58