Qbasicnews.com

Full Version: Why is this rasing errors? WinMM Stuff
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Code:
Declare Function midiOutClose Lib "winmm" (ByVal hMidiOut As Integer) As Integer
Declare Function midiOutGetVolume Lib "winmm" (ByVal uDeviceID As Integer, ByRef lpdwVolume As Integer) As Integer
Declare Function midiOutMessage Lib "winmm" (ByVal hMidiOut As Integer, ByVal msg As Integer, ByVal dw1 As Integer, ByVal dw2 As Integer) As Integer
Declare Function midiOutOpen Lib "winmm" (ByRef lphMidiOut As Integer, ByVal uDeviceID As Integer, ByVal dwCallback As Integer, ByVal dwInstance As Integer, ByVal dwFlags As Integer) As Integer
Declare Function midiOutReset Lib "winmm" (ByVal hMidiOut As Integer) As Integer
Declare Function midiOutSetVolume Lib "winmm" (ByVal uDeviceID As Integer, ByVal dwVolume As Integer) As Integer
Declare Function midiOutShortMsg Lib "winmm" (ByVal hMidiOut As Integer, ByVal dwMsg As Integer) As Integer


   ' MIDI Mapper
   Const MIDI_MAPPER As Byte = -1


   ' MIDI Controller Numbers Constants
   Const MOD_WHEEL As Byte = 1
   Const BREATH_CONTROLLER As Byte = 2
   Const FOOT_CONTROLLER As Byte = 4
   Const PORTAMENTO_TIME As Byte = 5
   Const MAIN_VOLUME As Byte = 7
   Const BALANCE As Byte = 8
   Const PAN As Byte = 10
   Const EXPRESS_CONTROLLER As Byte = 11
   Const DAMPER_PEDAL As Byte = 64
   Const PORTAMENTO As Byte = 65
   Const SOSTENUTO As Byte = 66
   Const SOFT_PEDAL As Byte = 67
   Const HOLD_2 As Byte = 69
   Const EXTERNAL_FX_DEPTH As Byte = 91
   Const TREMELO_DEPTH As Byte = 92
   Const CHORUS_DEPTH As Byte = 93
   Const DETUNE_DEPTH As Byte = 94
   Const PHASER_DEPTH As Byte = 95
   Const DATA_INCREMENT As Byte = 96
   Const DATA_DECREMENT As Byte = 97

   ' MIDI status messages
   Const NOTE_OFF As Byte = &H80
   Const NOTE_ON As Byte = &H90
   Const POLY_KEY_PRESS As Byte = &HA0
   Const CONTROLLER_CHANGE As Byte = &HB0
   Const PROGRAM_CHANGE As Byte = &HC0
   Const CHANNEL_PRESSURE As Byte = &HD0
   Const PITCH_BEND As Byte = &HE0

   ? "Hi"
   'The handle to the midi device
   dim hMidi as integer
  
   'the midi handle
   'the midi device you want to use in this case the default Windows Midi_Mapper
   'A callback function ... not being used here
   'A callback Instance ... not being used here
   'Flag, here its just CALLBACK_NULL ... i.e. not being used here
   midiOutOpen hmidi, MIDI_MAPPER, 0, 0, 0
   sleep
   midiOutClose hmidi
  
sleep

When I run this I get this:
Code:
c:\freebasic\midi_test_01.asm Assembler messages:
c:\freebasic\midi_test_01.asm:35:Error:suffix or operands invalid for 'movsx' on line:

I spent all day working up a lovely c++ bit to do Sound and Midi commands using the cross-platform, open source, Synthesis ToolKit (STK). I learned how to send midi messages, generate all kinds of tones, and have nice functions for each. I go to make a DLL and it won't work (works fine as a C++ console app). I realize that I am the worlds worse C programmer so I do the sensible thing and curse for a while and decide to do the midi stuff in Windows, in FB, with the winmm library.... and now this.

Sorry for the venting.
Constants should be converted a compile-time, fixed.. i was using the IR do to all the conversions, the AST is much capable now, so everything is being moved there, including all the parameters magic done in the background with strings.. mm..

Just remove the "as byte" for now, all integer constants are pushed as 32-bit ints anyway (less the longints, course)..
I got rid of all of the "as byte" bits and still got the same error. I removed all of the constants and it doesn't crash.

So when is the next version due.... :-)
You might want to look at BCX. It has a sound function that uses the midi subsystem. You should be able to create a DLL in BCX to do what you are wanting. In fact, I was thinking about doing just that to see if it would work, but I have been swamped lately with work. Maybe I can poke around with it today.
I was looking to do it in a manner that was easily ported over to a *nix environment. To my understanding, BCX's sound is tied to the winmm.dll. Hence the STK. The problem is that I'm not that hot at C++. I can get a working console app fine. Midi functions and sound generation galore! However, when I try to put the functions in a DLL, they don't work. I can call them, they show no errors, but no sound. :-(

So... since BCX will do the same thing with winmm that I would do in FreeBasic, why not do it in FreeBasic (until a gain a level or two in C programming). Perhaps the only advantage in BCX is that the routines are already made and tested. I have only a passing familiarity with BCX so I don't know. If you get it to work I would be interested in seeing it.
An alternative is to use FMOD as a general way to deal with audio from FB programs. FMOD runs on Win32 and Linux but the current version (3.74) supports MIDI playback only under Win32... Version 4 is said to support MIDI playback also under Linux when it's out, and it has been in the works for a long time, so I guess a good bet would be to use FMOD in your project for now and update to the newer version when it's out so your MIDIs will play also under Linux.
True, it is somthing to think about.

Although for now, I have midi working in FB. with calls to winmm. :-)