MIDIRequester

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

MIDIRequester

Post by BackupUser »

Code updated for 5.20+

Restored from previous forum. Originally posted by NicTheQuick.

I programmed a MIDIRequester to chose an in- or output device:

Code: Select all

Procedure MIDIRequester(*OutDevice, *InDevice)
  #MOD_WAVETABLE = 6
  #MOD_SWSYNTH = 7
  #MIDIRequ_InSet = 2
  #MIDIRequ_OutSet = 1
  
  #Width = 400
  If OpenWindow(0, 0, 0, #Width, 270, "MIDI-Requester", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    #Column = (#Width - 20) / 2
    #Offset = (#Width / 2) + 5
    
    TextGadget(0, 5, 5, #Column, 18, "Output-Device:", #PB_Text_Center | #PB_Text_Border)
    ListViewGadget(2, 5, 23, #Column, 100)
    MaxOutDev = midiOutGetNumDevs_()
    InfoOut.MIDIOUTCAPS
    If MaxOutDev
      For a = -1 To MaxOutDev - 1
        midiOutGetDevCaps_(a, InfoOut, SizeOf(MIDIOUTCAPS))
        AddGadgetItem(2, -1, PeekS(@InfoOut\szPname[0], 32))
      Next
    Else
      AddGadgetItem(2, -1, "(no output device)")
      DisableGadget(3, 1)
    EndIf
    
    TextGadget(1, #Offset, 5, #Column, 18, "Input-Device:", #PB_Text_Center | #PB_Text_Border)
    ListViewGadget(3, #Offset, 23, #Column, 100)
    MaxInDev = midiInGetNumDevs_()
    InfoIn.MIDIINCAPS
    If MaxInDev
      For a = 0 To MaxInDev - 1
        midiInGetDevCaps_(a, InfoIn, SizeOf(MIDIINCAPS))
        AddGadgetItem(3, -1, PeekS(@InfoIn\szPname[0], 32))
      Next
    Else
      AddGadgetItem(3, -1, "(no input device)")
      DisableGadget(3, 1)
    EndIf
    
    ButtonGadget(4, 5, 240, #Column, 24, "&OK")
    ButtonGadget(5, #Offset, 240, #Column, 24, "&Cancel")
    
    FrameGadget(6, 5, 130, #Width - 10, 100, "Info of Output-Device", 0)
    TextGadget(7, 10, 145, #Width - 20, 18, "Version:")
    TextGadget(8, 10, 165, #Width - 20, 18, "Technology:")
    TextGadget(9, 10, 185, #Width - 20, 18, "Max. Voices:")
    TextGadget(10, 10, 205, #Width - 20, 18, "Polyphonie:")
    
    OutDev = 0
    InDev = 0
    Quit = #False
    OK = #False
    Repeat
      If GetGadgetState(2) > -1 Or GetGadgetState(3) > -1
        DisableGadget(4, 0)
      Else
        DisableGadget(4, 1)
      EndIf
      
      If InDev <> GetGadgetState(3)
        InDev = GetGadgetState(3)
      EndIf
      
      If GetGadgetState(2) <> OutDev
        OutDev = GetGadgetState(2)
        midiOutGetDevCaps_(OutDev - 1, InfoOut, SizeOf(MIDIOUTCAPS))
        SetGadgetText(7, "Version: " + Str(InfoOut\vDriverVersion >> 8) + "." + Str(InfoOut\vDriverVersion & FF))
        Select InfoOut\wTechnology
          Case #MOD_MIDIPORT :  TmpS.s = "Hardware Port"
          Case #MOD_SYNTH :     TmpS.s = "Synthesizer"
          Case #MOD_SQSYNTH :   TmpS.s = "Square Wave Synthesizer"
          Case #MOD_FMSYNTH :   TmpS.s = "FM Synthesizer"
          Case #MOD_MAPPER :    TmpS.s = "Microsoft MIDI Mapper"
          Case #MOD_WAVETABLE : TmpS.s = "Hardware Wavetable Synthesizer"
          Case #MOD_SWSYNTH :   TmpS.s = "Software Synthesizer"
          Default: TmpS.s = "(Error Code " + Str(InfoOut\wTechnology) + ")"
        EndSelect
        SetGadgetText(8, "Technology: " + TmpS)
        If InfoOut\wVoices = 0 : TmpS.s = "inf" : Else : TmpS.s = Str(InfoOut\wVoices) : EndIf
        SetGadgetText(9, "Max. Voices: " + TmpS)
        If InfoOut\wNotes = 0 : TmpS.s = "inf" : Else : TmpS.s = Str(InfoOut\wNotes) : EndIf
        SetGadgetText(10, "Polyphonie: " + TmpS)
      EndIf
      
      EventID = WaitWindowEvent()
      Select EventID
        Case #PB_Event_CloseWindow
          Quit = #True
          OK = #False
        Case #PB_Event_Gadget
          Select EventGadget()
            Case 4
              PokeL(*OutDevice, OutDev - 1)
              PokeL(*InDevice, InDev)
              Quit = #True
              OK = 3
              If (OutDev = -1 Or CountGadgetItems(2) = 0) And OK & #MIDIRequ_OutSet : OK ! #MIDIRequ_OutSet : EndIf
              If (InDev = -1 Or CountGadgetItems(3) = 0) And OK & #MIDIRequ_InSet : OK ! #MIDIRequ_InSet : EndIf
            Case 5
              Quit = #True
              OK = #False
          EndSelect
      EndSelect
    Until Quit
    CloseWindow(0)
    ProcedureReturn OK
  Else
    End
  EndIf
EndProcedure

MIDIResult = MIDIRequester(@OutDevice, @InDevice)

If MIDIResult & #MIDIRequ_OutSet : Debug "Output device: " + Str(OutDevice) : EndIf
If MIDIResult & #MIDIRequ_InSet : Debug "Input device: " + Str(InDevice) : EndIf
End
Cu, NicTheQuick

Intel Celeron PPGA 466 Mhz, 192 MB SD-RAM, 2 Soundcards, 5 Synthesizer, ...
(16 years old german boy)
brandelh
New User
New User
Posts: 5
Joined: Tue Jan 24, 2006 1:34 am

Syntaxfehler

Post by brandelh »

Hallo,

der Compiler meckert hier:

SetGadgetText(7, "Version: " + Str(InfoOut\vDriverVersion >> Cool + "." + Str(InfoOut\vDriverVersion & FF))

Die fehlende Klammer nach Cool habe ich gefunden, da ich aber bisher wenig Erfahrung mit der Syntax in PureBasic habe (PowerBasic kenne ich länger) weiß das \ zu bedeuten hat.

\ scheint hier erlaubt zu sein, steht aber nicht in der Hilfe unter Operatoren. Was bewirkt dies in PureBasic ?

Beispiele: Select InfoOut\wTechnology
Case #MOD_MIDIPORT : TmpS.s = "Hardware Port"
If InfoOut\wVoices = 0 : Tmp

Tschüß
Hubert

PS: es zeigt die Ausgabegeräte für MIDI an, ich sollte das nun auch noch für MCI mit wav hinbekommen.
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Post by LuCiFeR[SD] »

this is the english forum... not all of us speak german, but I think I understand your problem...

try

Code: Select all

SetGadgetText(7, "Version: " + Str(InfoOut\vDriverVersion >> 8)  + "." + Str(InfoOut\vDriverVersion & FF))
that should work ;)

edit:

Code: Select all

Procedure MIDIRequester(*OutDevice.l, *InDevice.l)  
    #MOD_WAVETABLE = 6  
    #MOD_SWSYNTH = 7  
    #MIDIRequ_InSet = 2  
    #MIDIRequ_OutSet = 1  
    #Width = 400  
    
        If OpenWindow(0, 0, 0, #Width, 270, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "MIDI-Requester")    
            If CreateGadgetList(WindowID())  
                
            #Column = (#Width - 20) / 2      
            #Offset = (#Width / 2) + 5  
                
            TextGadget(0, 5, 5, #Column, 18, "Output-Device:", #PB_Text_Center | #PB_Text_Border)      
            ListViewGadget(2, 5, 23, #Column, 100)  
                  
            MaxOutDev.l = midiOutGetNumDevs_()        
            InfoOut.MIDIOUTCAPS   
                 
            If MaxOutDev          
                For a.l = -1 To MaxOutDev - 1            
                    midiOutGetDevCaps_(a, InfoOut, SizeOf(MIDIOUTCAPS))            
                    AddGadgetItem(2, -1, PeekS(@InfoOut\szPname[0], 32))          
                Next        
            Else          
                AddGadgetItem(2, -1, "(no output device)")          
                DisableGadget(3, 1)        
            EndIf
                  
            TextGadget(1, #Offset, 5, #Column, 18, "Input-Device:", #PB_Text_Center | #PB_Text_Border)      
            ListViewGadget(3, #Offset, 23, #Column, 100)        
            MaxInDev.l = midiInGetNumDevs_()        
            InfoIn.MIDIINCAPS        
            If MaxInDev          
                For a.l = 0 To MaxInDev - 1            
                    midiInGetDevCaps_(a, InfoIn, SizeOf(MIDIINCAPS))            
                    AddGadgetItem(3, -1, PeekS(@InfoIn\szPname[0], 32))          
                Next        
            Else          
                AddGadgetItem(3, -1, "(no input device)")          
                DisableGadget(3, 1)        
            EndIf 
                 
            ButtonGadget(4, 5, 240, #Column, 24, "&OK")      
            ButtonGadget(5, #Offset, 240, #Column, 24, "&Cancel")            
            Frame3DGadget(6, 5, 130, #Width - 10, 100, "Info of Output-Device", 0)       
            TextGadget(7, 10, 145, #Width - 20, 18, "Version:")       
            TextGadget(8, 10, 165, #Width - 20, 18, "Technology:")       
            TextGadget(9, 10, 185, #Width - 20, 18, "Max. Voices:")       
            TextGadget(10, 10, 205, #Width - 20, 18, "Polyphonie:")            
            OutDev.l = 0      
            InDev.l = 0      
            Quit.l = #False      
            OK.l = #False  
                
            Repeat        
                If GetGadgetState(2) > -1 Or GetGadgetState(3) > -1          
                    DisableGadget(4, 0)        
                Else          
                    DisableGadget(4, 1)        
                EndIf                
                If InDev.l <> GetGadgetState(3)          
                    InDev.l = GetGadgetState(3)        
                EndIf        
                If GetGadgetState(2) <> OutDev          
                    OutDev.l = GetGadgetState(2)          
                    midiOutGetDevCaps_(OutDev - 1, InfoOut, SizeOf(MIDIOUTCAPS))          
                    SetGadgetText(7, "Version: " + Str(InfoOut\vDriverVersion >>8)  + "." + Str(InfoOut\vDriverVersion & FF))  
                            
                    Select InfoOut\wTechnology            
                        Case #MOD_MIDIPORT :  TmpS.s = "Hardware Port"            
                        Case #MOD_SYNTH :     TmpS.s = "Synthesizer"            
                        Case #MOD_SQSYNTH :   TmpS.s = "Square Wave Synthesizer"            
                        Case #MOD_FMSYNTH :   TmpS.s = "FM Synthesizer"            
                        Case #MOD_MAPPER :    TmpS.s = "Microsoft MIDI Mapper"            
                        Case #MOD_WAVETABLE : TmpS.s = "Hardware Wavetable Synthesizer"            
                        Case #MOD_SWSYNTH :   TmpS.s = "Software Synthesizer"            
                        Default: TmpS.s = "(Error Code " + Str(InfoOut\wTechnology) + ")"          
                    EndSelect 
                             
                    SetGadgetText(8, "Technology: " + TmpS)          
                    If InfoOut\wVoices = 0 : TmpS.s = "inf" : Else : TmpS.s = Str(InfoOut\wVoices) : EndIf 
                             
                    SetGadgetText(9, "Max. Voices: " + TmpS)    
                          
                    If InfoOut\wNotes = 0 : TmpS.s = "inf" : Else : TmpS.s = Str(InfoOut\wNotes) : EndIf          
                    SetGadgetText(10, "Polyphonie: " + TmpS)        
                EndIf                
                EventID.l = WaitWindowEvent()        
                Select EventID          
                    Case #PB_EventCloseWindow            
                    Quit = #True            
                    OK = #False          
                    Case #PB_EventGadget            
                        Select EventGadgetID()              
                            Case 4                
                            PokeL(*OutDevice, OutDev - 1)                
                            PokeL(*InDevice, InDev)                
                            Quit = #True                
                            OK = 3                
                            If (OutDev = -1 Or CountGadgetItems(2) = 0) And OK & #MIDIRequ_OutSet : OK ! #MIDIRequ_OutSet : EndIf                
                            If (InDev = -1 Or CountGadgetItems(3) = 0) And OK & #MIDIRequ_InSet : OK ! #MIDIRequ_InSet : EndIf              
                            Case 5                
                            Quit = #True                
                            OK = #False            
                        EndSelect        
                EndSelect 
                     
            Until Quit      
            CloseWindow(0)      
            ProcedureReturn OK    
        Else      
            End    
        EndIf  
    Else    
        End  
    EndIf
EndProcedure
InDevice.l 
MIDIResult.l = MIDIRequester(@OutDevice, @InDevice)
If MIDIResult & #MIDIRequ_OutSet : Debug "Output device: " + Str(OutDevice) : EndIf
If MIDIResult & #MIDIRequ_InSet : Debug "Input device: " + Str(InDevice) : EndIf
End
That should work right out of the box now... excuse bad formatting (as it was rushed)

Hope that helps :) Working in PB 3.94
brandelh
New User
New User
Posts: 5
Joined: Tue Jan 24, 2006 1:34 am

Post by brandelh »

Hi,

sorry I was in the german forum and clicked on the link to this page. Not realizing that I jumped into the english forum.

I found the missing ')', but I don't know what the '\' stands for.
It looks like it is not an oparator, but what does it do ?

Ahh and now I know whats happend 8) went to a smily cool.
Now I know why [code]...[/code] is so important.

Bye
Hubert[/code]
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

It is for structured Variables.

Code: Select all

Structure Person
  Name.s
  ForName.s 
  Age.w 
EndStructure

a.Person

a\Name = "Mustermann"
a\ForName = "Max"
a is structured or Type of Person
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply