Simple midi - IN, OUT '& THRU demonstrated and Midi FAQ


Author: Stefaan Casier

Simple midi - IN, OUT & THRU demonstrated

This sample project by Stefaan Casier demonstrates some of the simpler MIDI programming techniques used in his excellent MIDI programming article here on CodeGuru. This time around, the simple concepts are explained, along with a MIDI programming FAQ for Visual Basic. The program shows how to play certain notes using the MIDI interface and analyse notes coming into the computer also.

screen-shot

PROJECT NAME
 	midi.vbp

PURPOSE
	Based on the reactions on my BulkDump project,
	there seems to be much demand for a simple midi project
	that demonstrates the basics. The BulkDump project
	was maybe to large to dig into. This one is small and
	easier.

ENVIRONMENT
	This is a VB5 project, which will run under Windows 9x.
	No other than basic VB-controls are used.

YOU CAN LEARN
	How to send notes to the midi OUT-port
	How to make a midi THRU connection
	How to read & analyse incoming messages from a midi keyboard
	...

COPYRIGHT
	None. I made the code myself and everybody is free
	to use it.

RUNTIME FILES
	executable is not included

CODE FILES
	midi.vbp/.vbw

	frmMidi.frm
	frmDevCap.frm

	midi.bas

ADDITIONAL FILE
	faq.htm : questions and answers + midi IN info

Download Zipped Project (10k)
Download Midi Programming FAQ (html format) (10k)



Comments

  • Great tool for REAL pipe organs

    Posted by Craig Whitley on 01/13/2014 01:12pm

    I know this is a moldy oldie program but it is great for using my laptop in the pipe organ chamber as an aid in tuning the pipes without anyone at the organ console. I simply add in code to turn on or off various ranks of pipes then use the VB MIDI keyboard to turn on/off the pipe being tuned. I have a wireless Ethernet MIDI program running on both my laptop and the console computer. Thanks greatly for this program.

    Reply
  • works in VB6, crashes as a compiled exe

    Posted by hockinfinger on 04/09/2004 08:23am

    Using this code, I've written an app to send sysex data to my SC55 while allowing me to play notes on my keyboard connected to the midi input. My app works fine in the VB6 evironment, but as a compiled exe, it crashes as soon as the midiin_port sub is called. I suspect the problem may have something to do with the callbacks, but I still consider myself a novice, so I can't say for sure. Is there a way to play a midi keyboard connected to the input thru the output, and send sysex to the output at the same time without the callbacks? I am using Windows XP and a M-Audio DMAN PCI card with a Crystal Soundfusion driver. Any help would be greatly appreciated.

    • works in VB6, crashes as a compiled exe

      Posted by sta_dk on 01/27/2005 01:54pm

      Did anyone ever manage to explain the reason for crashing when compiled as exe? I've run into the same problem. Works fine in the VB6 environment. /Stefan

      Reply
    Reply
  • best around

    Posted by Legacy on 09/17/2003 12:00am

    Originally posted by: Mick H S

    this has interesting method for creating visual keyboard and the code can be modifyed to suite a number of midi applications. change variables mMPU401OUT = 256 to 1 and
    mMPU401IN = 256 to 0 will get this code working but can anybody help beginner get round the crash prblem when compiled ?
    on the whole excelent code

    Reply
  • NICE CODE BUT I AM HAVING PROBLEMS - HELP ME SOMEONE

    Posted by Legacy on 12/30/2002 12:00am

    Originally posted by: PIERRE DENIS

    EVER SINCE I HAVE BEEN TRYING TO READ THE MIDI IN PORT
    
    VIA WINDOWS API , IN VB, WHATEVER CODE EXAMPLE I COULD FIND WOULD RESULT IN THE SAME TWO PROBLEMS...

    - WITHIN THE VB 5.0 SHELL, ONCE THE CALLBACK FUNCTION IS
    CALLED FOR THE FIRST TIME, ANY OTHER ACTION ON MY PROJECT
    INCLUDING STOPING IT WOULD RESULT IN A GPF CAUSED BY VB.
    ONLY THE COMPILED .EXE PROJECT WORKS WITHOUT ANY GPF'S

    - WHEN USING A COMPILED PROGRAM, THE CALLBACK FUNCTION
    RECEIVES THE MIDI_OPEN SIGNAL AND THEN NOTHING....

    PLEASE POST ANY ADVISE TO SOLVE THESE PROBLEMS TO

    pdenis001@sympatico.ca

    Reply
  • Nice introduction

    Posted by Legacy on 07/09/2002 12:00am

    Originally posted by: stb

    Hi,

    I'm a professional software developer but I'm clueless about midi programming. I try to find some code samples (C++, VB or Delphi) about midi cc. I want to make a software for controlling hardware like digital effect processor for guitar. I guess that I have to provide a midi in/out interface, a midi channel, a midi cc and a value to a function or an event. But I have no idea how to do that.

    STB
    www.onlinerock.com/musicians/stb

    Reply
  • Help with using Windows MIDI API Calls

    Posted by Legacy on 12/14/2001 12:00am

    Originally posted by: Eric Ambrosino

    Hello MIDI / VB expert,

    I'm looking for some help for a simple VB 6.0 MIDI application. I need to learn how to make better use of the Windows API. Right now my app works ok but needs to know the base address of the MIDI output port. I then write the MIDI status and data bytes directly to the MIDI out port at that address in UART pass through mode. My questions are:

    Your cool example looks like the one I've been looking for.
    I am using your original VB code from your MIDI Keyboard MIDI IN, OUT, and THRU example on several PC's and one error keeps coming up on all the PC's saying that "A device is out of the range for your system". Any ideas or can this be due to the old MIDI Mapper? Same error comes up on the MIDI IN port as well.

    The other problem is I first ran your code w/VB 6.0 at a screen res of 1600 by 1200 and the keyboard gets cut off at the right hand end. (about a 1/4 of the upper keyboard) I really just need a form that I can call that will take care of all the MIDI IN, OUT and THRU stuff and let the user make the select without errors poping up.

    This was my original text prior to finding your COOl example!

    1. I need an example of how to use the API's midiOutOpen,
    midiOutGetNumDevs, midiOutShortMsg, midiOutLongMsg and
    midiOutClose as applied in Visual Basic 5.0 or 6.0. These API's I believe, will find what MIDI hardware is in the PC and will take care of all that base address and base address + 1 stuff for me.

    I've seen excellent examples of the above mentioned API calls using "C" code examples. Sorry, but I'm a hardware guy and VB is more my speed for windows programming.

    2. My other question is how to make/steer the MIDI data to the internal sound card's wave table instead of just going out through the MPU 401 in UART mode using the MIDI cable via the game port. My application works on the external MIDI sound device but I can't seem to get it to sound the internal PC's wave table sound card. Again, this is better handled with a form that lets the user
    select their various MIDI devices and let that VB form use API calls to do the real low level stuff i.e. writing / reading to the port address of a user's selected sound source. Hope you can help me out and appreciate you time.

    Thanks for reading and any help you can give me!

    Eric Ambrosino
    eric.ambrosino@hs.utc.com

    Reply
  • Comment

    Posted by Legacy on 10/14/2001 12:00am

    Originally posted by: Jen Keenan

    This should help me with my project! Thanx m8

    Reply
  • Congratulations! very good...very good!

    Posted by Legacy on 09/07/2001 12:00am

    Originally posted by: ROSALBA-MEXICO

    is a hard code..very easy by understood
    bye

    Reply
  • Very compact and valueable code - congratulations!

    Posted by Legacy on 04/14/2001 12:00am

    Originally posted by: Andreas

    Hi Stefaan,

    if you ever should read my comment: congratulation! You provide us all with a really fine piece of code.

    Actually, it solved lots of problems I encountered when writing my Final Year Project at the University of Derby in Austria (it's a FuzzyLogic driven controller for drum-computers in order to provide the best available rhythm pattern for the current keyboarder's style).

    Thanks,
    Andreas.

    Reply
  • A great trip to midi! - Some additions to the program...

    Posted by Legacy on 03/18/2001 12:00am

    Originally posted by: Steve

    This little program is the best thing I could find on the web! :o) All others are incomplete or just superficial.

    - This tool provides all midi in and out code you need to make simple controler or note sending software when working with synthesizers. - Great job! :o)

    But I experienced some problems and my hints may save you some time:
    I do not have a MOTU card and somehow the program expects that you are using one. I had to change all MOTU variables to the midi-port no. I am using and then it worked. (I think I remember that if you have no MOTU card the port is set to 256 which is not a valid port - should be 0, 1, 2 or so...)

    A second problem (probably is not a problem of this sample software) was that the callback_function caused a unexpected program termination by the VB6run. It workes fine, as long as I am working in the VB6 environment but the compiled version causes the described problem. When callback_function is disabled (or just not used) it works fine. (The callback function is used when you want to process incoming midi data and i.e. send it out again. If you just need to send data by software or use a midi-thru than you do not need the callback_function)

    Hope that saves you some time ;o)


    Steve

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • Packaged application development teams frequently operate with limited testing environments due to time and labor constraints. By virtualizing the entire application stack, packaged application development teams can deliver business results faster, at higher quality, and with lower risk.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds