Using Win32 functions in Visual FoxPro Image Gallery
Windows Multimedia
..msdn
AVIFileExit
AVIFileGetStream
AVIFileInfo
AVIFileInit
AVIFileOpen
AVIFileRelease
AVIFileWriteData
AVIStreamGetFrame
AVIStreamGetFrameClose
AVIStreamGetFrameOpen
AVIStreamInfo
AVIStreamLength
AVIStreamReadFormat
AVIStreamRelease
AVIStreamStart
AVIStreamTimeToSample
capCreateCaptureWindow
capGetDriverDescription
DrawDibClose
DrawDibDraw
DrawDibOpen
mciGetDeviceID
mciGetErrorString
mciSendCommand
mciSendString
midiOutClose
midiOutGetDevCaps
midiOutGetNumDevs
midiOutOpen
midiOutReset
midiOutShortMsg
mixerClose
mixerGetControlDetails
mixerGetDevCaps
mixerGetID
mixerGetLineControls
mixerGetLineInfo
mixerGetNumDevs
mixerOpen
mixerSetControlDetails
mmioAscend
mmioClose
mmioCreateChunk
mmioDescend
mmioFlush
mmioOpen
mmioRead
mmioSeek
mmioWrite
PlaySound
sndPlaySound
timeGetDevCaps
waveInAddBuffer
waveInClose
waveInGetDevCaps
waveInGetErrorText
waveInGetNumDevs
waveInGetPosition
waveInOpen
waveInPrepareHeader
waveInReset
waveInStart
waveInStop
waveInUnprepareHeader
waveOutClose
waveOutGetDevCaps
waveOutGetErrorText
waveOutGetNumDevs
waveOutGetPosition
waveOutGetVolume
waveOutOpen
waveOutPrepareHeader
waveOutReset
waveOutSetVolume
waveOutUnprepareHeader
waveOutWrite
Code examples:
Enumerating MIDI output devices
How to play MIDI notes
How to play MIDI notes

User rating: 10/10 (1 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:
Set the note in 0-127 range and the velocity (how hard the key is pressed) in 20-200+ range and press Enter. Also you can select a program -- an emultaion of a musical instrument the note to be played with.

The "Demo Sound" button shows how simple custom MIDI sounds can be used in VFP application.


See also:
  • How to play a waveform sound
  • Playing WAV sounds simultaneously
  • WAV file player
  •  
    oForm = CREATEOBJECT("Tform")
    oForm.Show(1)
    * end of main
     
    DEFINE CLASS Tform AS form
    PROTECTED midi
        midi=NULL
        Height=182
        Width=316
        AutoCenter=.T.
        Caption="Play MIDI Notes"
        MaxButton=.F.
        MinButton=.F.
     
        ADD OBJECT Label1 AS Label WITH AutoSize=.T.,;
            BackStyle=0, Caption="Sound:", Height=17,;
            Left=14, Top=20, Width=31
     
        ADD OBJECT cmbProgram As ComboBox WITH Left=62,;
            Top=15, Width=120, Height=24, Style=2
     
        ADD OBJECT Label2 AS Label WITH AutoSize=.T.,;
            BackStyle=0, Caption="Note (0 to 127)", Height=17,;
            Left=14, Top=62, Width=31
     
        ADD OBJECT txtNote AS Spinner WITH Height=24,;
            KeyboardHighValue=127, KeyboardLowValue=0, Left=12,;
            SpinnerHighValue=127, SpinnerLowValue=0,;
            Top=86, Width=85, Value=48
     
        ADD OBJECT Label3 AS Label WITH AutoSize=.T.,;
            BackStyle=0, Caption="Velocity:", Height=17,;
            Left=120, Top=62, Width=46
     
        ADD OBJECT txtVelocity AS Spinner WITH Height=24,;
            KeyboardHighValue=200, KeyboardLowValue=20, Left=108,;
            SpinnerHighValue=200, SpinnerLowValue=20, Top=86,;
            Width=85, Value=100
     
        ADD OBJECT cmdPlay AS CommandButton WITH Top=86,;
            Left=200, Height=27, Width=48,;
            Caption="Play", Default=.T.
     
        ADD OBJECT cmdStop AS CommandButton WITH Top=86,;
            Left=250, Height=27, Width=48,;
            Caption="Stop", Default=.T.
     
        ADD OBJECT cmdDemo AS CommandButton WITH Top=140,;
            Left=12, Height=27, Width=100,;
            Caption="Demo Sound", Default=.T.
     
    PROCEDURE Init
        THIS.midi = CREATEOBJECT("TMidiNote")
        ThisForm.ChangePatch
     
    PROCEDURE cmbProgram.Init
        LOCAL nIndex
        FOR nIndex=0 TO 127
            THIS.AddItem("Program " + LTRIM(STR(nIndex)))
        NEXT
        THIS.ListIndex=1
     
    PROCEDURE cmbProgram.InteractiveChange
        ThisForm.ChangePatch
     
    PROCEDURE cmdDemo.Click
        ThisForm.PlayDemoSound
     
    PROCEDURE cmdPlay.Click
        ThisForm.PlayNote
     
    PROCEDURE cmdStop.Click
        ThisForm.StopNote
     
    PROCEDURE PlayDemoSound
        THIS.midi.ChangePatch(117)
        THIS.midi.PlayNote(54, 100)
        Sleep(150)
        THIS.midi.PlayNote(50, 100)
        Sleep(100)
        THIS.midi.PlayNote(48, 100)
        Sleep(70)
        THIS.midi.PlayNote(44, 100)
     
        DOEVENTS
        THIS.ChangePatch
     
    PROCEDURE ChangePatch
        LOCAL nProgram
        nProgram = THIS.cmbProgram.ListIndex-1
        THIS.midi.ChangePatch(m.nProgram)
     
    PROCEDURE StopNote
        LOCAL nNote
        nNote = THIS.txtNote.Value
        THIS.midi.StopNote(m.nNote)
     
    PROCEDURE PlayNote
        LOCAL nNote, nVelocity
        nNote = THIS.txtNote.Value
        nVelocity = THIS.txtVelocity.Value
        THIS.midi.PlayNote(nNote, nVelocity)
     
    ENDDEFINE
     
    DEFINE CLASS TMidiNote As Session
    #DEFINE MIDI_STATUS_PLAYNOTE 9
    #DEFINE MIDI_STATUS_PATCH 12
    PROTECTED hDevice, channel
        hDevice=0
        channel=0
     
    PROCEDURE Init(lDeclare)
        THIS.declare
        IF NOT THIS.OpenDevice()
            RETURN .F.
        ENDIF
     
    PROCEDURE Destroy
        THIS.CloseDevice
     
    PROTECTED FUNCTION OpenDevice() As Boolean
        IF midiOutGetNumDevs() = 0
            MESSAGEBOX("No Midi Devices found.",;
                48, "MIDI Error")
            RETURN .F.
        ENDIF
     
        LOCAL hDevice, nResult
        hDevice=0
        nResult = midiOutOpen(@hDevice, 0,0,0,0)
        THIS.hDevice = m.hDevice
        IF nResult <> 0
            MESSAGEBOX("Call to midiOutOpen failed: " +;
                TRANSFORM(nResult), 48, "MIDI Error")
        ENDIF
    RETURN (m.nResult=0)
     
    PROTECTED PROCEDURE CloseDevice
        IF THIS.hDevice <> 0
            = midiOutReset(THIS.hDevice)
            = midiOutClose(THIS.hDevice)
            THIS.hDevice = 0
        ENDIF
     
    PROCEDURE SendMIDICommand(b1, b2, b3, b4)
        IF THIS.hDevice <> 0
            LOCAL nMsg, nResult
            nMsg = THIS.channel + BITLSHIFT(m.b1,4) +;
                BITLSHIFT(m.b2,8) +;
                BITLSHIFT(m.b3,16) + BITLSHIFT(m.b4,24)
     
            nResult = midiOutShortMsg(THIS.hDevice, m.nMsg)
            IF nResult <> 0
                MESSAGEBOX("Call to midiOutShortMsg failed: " +;
                    TRANSFORM(nResult), 48, "MIDI Error")
            ENDIF
        ENDIF
     
    PROCEDURE PlayNote(nNote, nVelocity)
        THIS.SendMIDICommand(MIDI_STATUS_PLAYNOTE,;
            nNote, nVelocity, 0)
     
    PROCEDURE StopNote(nNote)
        THIS.SendMIDICommand(MIDI_STATUS_PLAYNOTE,;
            m.nNote, 0, 0)
     
    PROCEDURE ChangePatch(nPatchNo)
        THIS.SendMIDICommand(MIDI_STATUS_PATCH,;
            nPatchNo, 0, 0)
     
    PROCEDURE declare
        DECLARE INTEGER midiOutGetNumDevs IN Winmm
        DECLARE INTEGER midiOutClose IN Winmm INTEGER hmo  
        DECLARE INTEGER midiOutReset IN Winmm INTEGER hmo  
        DECLARE Sleep IN kernel32 INTEGER dwMilliseconds
     
        DECLARE INTEGER midiOutOpen IN Winmm;
            INTEGER @lphmo, INTEGER uDeviceID, INTEGER dwCallback,;
            INTEGER dwCallbackInstance, INTEGER dwFlags
     
        DECLARE INTEGER midiOutShortMsg IN Winmm;
            INTEGER hmo, LONG dwMsg    
     
    ENDDEFINE
     

    User rating: 10/10 (1 votes)
    Rate this code sample:
    • ~
    4497 bytes  
    Created: 2008-04-09 19:38:20  
    Modified: 2008-04-14 18:43:03  
    Visits in 7 days: 127  
    Listed functions:
    midiOutClose
    midiOutGetNumDevs
    midiOutOpen
    midiOutReset
    midiOutShortMsg
    Sleep
    Printer friendly API declarations
    My comment:
    This is a list of MIDI instruments (a.k.a. voices, timbres, programs and patches):
    0. AcousticGrandPiano
    1. BrightAcousticPiano
    2. ElectricGrandPiano
    3. HonkyTonkPiano
    4. ElectricPiano1
    5. ElectricPiano2
    6. Harpsichord
    7. Clavi
    8. Celesta
    9. Glockenspiel
    10. MusicBox
    11. Vibraphone
    12. Marimba
    13. Xylophone
    14. TubularBells
    15. Dulcimer
    16. DrawbarOrgan
    17. PercussiveOrgan
    18. RockOrgan
    19. ChurchOrgan
    20. ReedOrgan
    21. Accordion
    22. Harmonica
    23. TangoAccordion
    24. AcousticGuitarNylon
    25. AcousticGuitarSteel
    26. ElectricGuitarJazz
    27. ElectricGuitarClean
    28. ElectricGuitarMuted
    29. OverdrivenGuitar
    30. DistortionGuitar
    31. GuitarHarmonics
    32. AcousticBass
    33. ElectricBassFinger
    34. ElectricBassPick
    35. FretlessBass
    36. SlapBass1
    37. SlapBass2
    38. SynthBass1
    39. SynthBass2
    40. Violin
    41. Viola
    42. Cello
    43. Contrabass
    44. TremoloStrings
    45. PizzicatoStrings
    46. OrchestralHarp
    47. Timpani
    48. StringEnsemble1
    49. StringEnsemble2
    50. SynthStrings1
    51. SynthStrings2
    52. ChoirAahs
    53. VoiceOohs
    54. SynthVoice
    55. OrchestraHit
    56. Trumpet
    57. Trombone
    58. Tuba
    59. MutedTrumpet
    60. FrenchHorn
    61. BrassSection
    62. SynthBrass1
    63. SynthBrass2
    64. SopranoSax
    65. AltoSax
    66. TenorSax
    67. BaritoneSax
    68. Oboe
    69. EnglishHorn
    70. Bassoon
    71. Clarinet
    72. Piccolo
    73. Flute
    74. Recorder
    75. PanFlute
    76. BlownBottle
    77. Shakuhachi
    78. Whistle
    79. Ocarina
    80. Lead1Square
    81. Lead2Sawtooth
    82. Lead3Calliope
    83. Lead4Chiff
    84. Lead5Charang
    85. Lead6Voice
    86. Lead7Fifths
    87. Lead8BassPluslead
    88. Pad1NewAge
    89. Pad2Warm
    90. Pad3Polysynth
    91. Pad4Choir
    92. Pad5Bowed
    93. Pad6Metallic
    94. Pad7Halo
    95. Pad8Sweep
    96. FX1Rain
    97. FX2Soundtrack
    98. FX3Crystal
    99. FX4Atmosphere
    100. FX5Brightness
    101. FX6Goblins
    102. FX7Echoes
    103. FX8SciFi
    104. Sitar
    105. Banjo
    106. Shamisen
    107. Koto
    108. Kalimba
    109. Bagpipe
    110. Fiddle
    111. Shanai
    112. TinkleBell
    113. Agogo
    114. SteelDrums
    115. Woodblock
    116. TaikoDrum
    117. MelodicTom
    118. SynthDrum
    119. ReverseCymbal
    120. GuitarFretNoise
    121. BreathNoise
    122. Seashore
    123. BirdTweet
    124. TelephoneRing
    125. Helicopter
    126. Applause
    127. Gunshot
    Word Index links for this example:
    Translate this page:
      Spanish    Portuguese    German    French    Italian  
    FreeTranslation.com offers instant, free translations of text or web pages.
    User Contributed Notes:
    There are no notes on this subject.


    Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

    Privacy policy
    Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (23.22.76.170)
    3 sec.Function: 'StartService'
    2.23 hrs.Example: 'How to suspend or hibernate your system'
     
    Function group: 'Filled Shape'
    3.62 hrs.Example: 'Locking the workstation'
     Function: 'SetSysColors'
    Function group: 'System Information'
     Example: 'Using Month Calendar Control (VFP9, Comctl32.dll)'
    7.44 hrs.Example: 'Enumerating forms supported by a specified printer'
    13.67 hrs.Function: 'GetPriorityClipboardFormat'
    Function group: 'Clipboard'
    19.04 hrs.Function: 'ClientToScreen'
    Function group: 'Coordinate Space and Transformation'
    21.57 hrs.Function: 'GetACP'
    Function group: 'National Language Support'
    Google
    Advertise here!