This project has moved and is read-only. For the latest updates, please go here.

MidiInPort and controlling some graphic

Topics: Midi IO, MidiPort
Nov 21, 2014 at 7:49 PM
I built the source code and rebuilded solution with no errors and on project added those four dll files to reference.

Now, i would like to add the code for MidiInPort in the project that already exist, so that i can via midi keyboard manipulate with certain graphics.
Let's say that we want with certain key - switch an image. So, when we press let's say note C4, that will switch an image and after releasing the key first one will again appear and so on...

What would look the simplest form of the code for this purpose and where it should be placed, in form.vb or elsewhere?
When i try to put any code with using CannedBytes.Midi, this error apear "Statement cannot appear outside of a method body/multiline lambda"
Sorry im not any expert in this, so i would realy appreciate any help:)

Nov 22, 2014 at 7:31 AM
The error indicates that the code you've added is not in a valid location. You have placed it outside a method (probably). I do not mind helping with MIDI.NET, but I do ask that people 'do their homework'.

You have to implement the IMidiDataReceiver interface and set it as 'Successor' on the MidiInPort. See also Getting Started in the docs.

The LongData method can be ignored for now - just implement an empty method. The ShortData will receive the incoming MIDI data. You may have to filter that data for NoteOn and NoteOff events. If you're fine working with MIDI data as int's then perhaps the MidiData class can help you deciding what the MIDI events are.

If you prefer to receive your MIDI data as objects, you can use CreateShortMessage method of the MidiMessageFactory to create the MidiShortMessage objects. The factory will return different types of objects (all derived from MidiShortMessage) for each different Midi event.

Hope it helps,
Nov 24, 2014 at 4:09 PM
At the first i started my project with .vb class, now i wonder how to implement this .cs classes or connect to it?:)
Nov 24, 2014 at 5:18 PM
.cs files are C-Sharp (C#) files which is a different langauge than VB.NET.

The type of project you create dictates the language. You CAN use .NET assemblies in any language in any other language (technically not entirely true, but it is for VB.NET vs CS).

This tool may help in converting the C# sample code to VB.NET.