home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Game Programming for Teens / VBGPFT.cdr / DirectX8 / dx8vbsdk.exe / samples / multimedia / vbsamples / directmusic / audiopath / frmaudiopath.frm (.txt) next >
Encoding:
Visual Basic Form  |  2000-10-02  |  33.5 KB  |  959 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
  3. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  4. Begin VB.Form frmAudioPath 
  5.    BorderStyle     =   3  'Fixed Dialog
  6.    Caption         =   "vbAudioPath Sample"
  7.    ClientHeight    =   5700
  8.    ClientLeft      =   720
  9.    ClientTop       =   780
  10.    ClientWidth     =   7965
  11.    Icon            =   "frmAudioPath.frx":0000
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   5700
  16.    ScaleWidth      =   7965
  17.    StartUpPosition =   3  'Windows Default
  18.    Begin VB.Timer tmrUpdate 
  19.       Interval        =   50
  20.       Left            =   8820
  21.       Top             =   660
  22.    End
  23.    Begin MSComDlg.CommonDialog cdlOpen 
  24.       Left            =   8820
  25.       Top             =   3120
  26.       _ExtentX        =   847
  27.       _ExtentY        =   847
  28.       _Version        =   393216
  29.    End
  30.    Begin VB.Frame fraPath 
  31.       Caption         =   "Audio Path 1 (Primary)"
  32.       Height          =   4095
  33.       Index           =   0
  34.       Left            =   0
  35.       TabIndex        =   31
  36.       Top             =   1500
  37.       Width           =   2595
  38.       Begin VB.TextBox txtPrimary 
  39.          Height          =   285
  40.          Left            =   60
  41.          Locked          =   -1  'True
  42.          TabIndex        =   16
  43.          Top             =   1620
  44.          Width           =   2175
  45.       End
  46.       Begin VB.CommandButton cmdAdd 
  47.          Caption         =   "..."
  48.          Height          =   300
  49.          Index           =   0
  50.          Left            =   2220
  51.          TabIndex        =   15
  52.          Top             =   1620
  53.          Width           =   315
  54.       End
  55.       Begin VB.CheckBox chkLoop 
  56.          Caption         =   "Loop"
  57.          Height          =   195
  58.          Index           =   0
  59.          Left            =   120
  60.          TabIndex        =   14
  61.          Top             =   2040
  62.          Width           =   735
  63.       End
  64.       Begin MSComctlLib.Slider sldX 
  65.          Height          =   135
  66.          Index           =   0
  67.          Left            =   300
  68.          TabIndex        =   18
  69.          Top             =   3360
  70.          Width           =   2235
  71.          _ExtentX        =   3942
  72.          _ExtentY        =   238
  73.          _Version        =   393216
  74.          Min             =   -20
  75.          Max             =   20
  76.          TickFrequency   =   5
  77.       End
  78.       Begin VB.CommandButton cmdStop 
  79.          Caption         =   "Stop"
  80.          Height          =   315
  81.          Index           =   0
  82.          Left            =   900
  83.          TabIndex        =   13
  84.          Top             =   1980
  85.          Width           =   795
  86.       End
  87.       Begin VB.CommandButton cmdPlay 
  88.          Caption         =   "Play"
  89.          Height          =   315
  90.          Index           =   0
  91.          Left            =   1740
  92.          TabIndex        =   12
  93.          Top             =   1980
  94.          Width           =   795
  95.       End
  96.       Begin MSComctlLib.Slider sldY 
  97.          Height          =   135
  98.          Index           =   0
  99.          Left            =   300
  100.          TabIndex        =   19
  101.          Top             =   3600
  102.          Width           =   2235
  103.          _ExtentX        =   3942
  104.          _ExtentY        =   238
  105.          _Version        =   393216
  106.          Min             =   -20
  107.          Max             =   20
  108.          TickFrequency   =   5
  109.       End
  110.       Begin MSComctlLib.Slider sldZ 
  111.          Height          =   135
  112.          Index           =   0
  113.          Left            =   300
  114.          TabIndex        =   20
  115.          Top             =   3840
  116.          Width           =   2235
  117.          _ExtentX        =   3942
  118.          _ExtentY        =   238
  119.          _Version        =   393216
  120.          Min             =   -20
  121.          Max             =   20
  122.          TickFrequency   =   5
  123.       End
  124.       Begin MSComctlLib.Slider sldVolume 
  125.          Height          =   135
  126.          Index           =   0
  127.          Left            =   120
  128.          TabIndex        =   17
  129.          Top             =   2940
  130.          Width           =   2415
  131.          _ExtentX        =   4260
  132.          _ExtentY        =   238
  133.          _Version        =   393216
  134.          LargeChange     =   500
  135.          SmallChange     =   100
  136.          Min             =   -6000
  137.          Max             =   0
  138.          TickFrequency   =   1000
  139.       End
  140.       Begin VB.Label lbl 
  141.          BackStyle       =   0  'Transparent
  142.          Caption         =   $"frmAudioPath.frx":0442
  143.          Height          =   1035
  144.          Index           =   21
  145.          Left            =   120
  146.          TabIndex        =   53
  147.          Top             =   240
  148.          Width           =   2415
  149.       End
  150.       Begin VB.Label lbl 
  151.          BackStyle       =   0  'Transparent
  152.          Caption         =   "Z"
  153.          Height          =   255
  154.          Index           =   10
  155.          Left            =   120
  156.          TabIndex        =   42
  157.          Top             =   3780
  158.          Width           =   195
  159.       End
  160.       Begin VB.Label lbl 
  161.          BackStyle       =   0  'Transparent
  162.          Caption         =   "Y"
  163.          Height          =   255
  164.          Index           =   9
  165.          Left            =   120
  166.          TabIndex        =   41
  167.          Top             =   3600
  168.          Width           =   255
  169.       End
  170.       Begin VB.Label lbl 
  171.          BackStyle       =   0  'Transparent
  172.          Caption         =   "X"
  173.          Height          =   255
  174.          Index           =   8
  175.          Left            =   120
  176.          TabIndex        =   40
  177.          Top             =   3360
  178.          Width           =   195
  179.       End
  180.       Begin VB.Label lbl 
  181.          BackStyle       =   0  'Transparent
  182.          Caption         =   "3D Positioning"
  183.          Height          =   255
  184.          Index           =   7
  185.          Left            =   120
  186.          TabIndex        =   39
  187.          Top             =   3120
  188.          Width           =   2415
  189.       End
  190.       Begin VB.Label lbl 
  191.          BackStyle       =   0  'Transparent
  192.          Caption         =   "Volume (hundredths of a decibel)"
  193.          Height          =   255
  194.          Index           =   6
  195.          Left            =   120
  196.          TabIndex        =   38
  197.          Top             =   2700
  198.          Width           =   2415
  199.       End
  200.       Begin VB.Label lbl 
  201.          BackStyle       =   0  'Transparent
  202.          Caption         =   "Audio Path Settings"
  203.          Height          =   255
  204.          Index           =   3
  205.          Left            =   120
  206.          TabIndex        =   35
  207.          Top             =   2460
  208.          Width           =   2415
  209.       End
  210.       Begin VB.Label lbl 
  211.          BackStyle       =   0  'Transparent
  212.          Caption         =   "File in Audio Path"
  213.          Height          =   255
  214.          Index           =   0
  215.          Left            =   120
  216.          TabIndex        =   32
  217.          Top             =   1380
  218.          Width           =   2415
  219.       End
  220.    End
  221.    Begin VB.Frame fraPath 
  222.       Caption         =   "Audio Path 3 (Secondary)"
  223.       Height          =   4095
  224.       Index           =   2
  225.       Left            =   5280
  226.       TabIndex        =   30
  227.       Top             =   1500
  228.       Width           =   2595
  229.       Begin VB.CheckBox chkLoop 
  230.          Caption         =   "Loop"
  231.          Height          =   195
  232.          Index           =   2
  233.          Left            =   1740
  234.          TabIndex        =   2
  235.          Top             =   1440
  236.          Width           =   735
  237.       End
  238.       Begin VB.CommandButton cmdStop 
  239.          Caption         =   "Stop"
  240.          Height          =   315
  241.          Index           =   2
  242.          Left            =   1680
  243.          TabIndex        =   0
  244.          Top             =   2100
  245.          Width           =   795
  246.       End
  247.       Begin VB.CommandButton cmdPlay 
  248.          Caption         =   "Play"
  249.          Height          =   315
  250.          Index           =   2
  251.          Left            =   1680
  252.          TabIndex        =   1
  253.          Top             =   1740
  254.          Width           =   795
  255.       End
  256.       Begin VB.CommandButton cmdRemove 
  257.          Caption         =   "Remove"
  258.          Height          =   315
  259.          Index           =   2
  260.          Left            =   1680
  261.          TabIndex        =   3
  262.          Top             =   960
  263.          Width           =   795
  264.       End
  265.       Begin VB.CommandButton cmdAdd 
  266.          Caption         =   "Add"
  267.          Height          =   315
  268.          Index           =   2
  269.          Left            =   1680
  270.          TabIndex        =   4
  271.          Top             =   600
  272.          Width           =   795
  273.       End
  274.       Begin VB.ListBox lstPath 
  275.          Height          =   1815
  276.          Index           =   2
  277.          Left            =   120
  278.          TabIndex        =   5
  279.          Top             =   600
  280.          Width           =   1515
  281.       End
  282.       Begin MSComctlLib.Slider sldVolume 
  283.          Height          =   135
  284.          Index           =   2
  285.          Left            =   60
  286.          TabIndex        =   25
  287.          Top             =   2940
  288.          Width           =   2415
  289.          _ExtentX        =   4260
  290.          _ExtentY        =   238
  291.          _Version        =   393216
  292.          LargeChange     =   500
  293.          SmallChange     =   100
  294.          Min             =   -6000
  295.          Max             =   0
  296.          TickFrequency   =   1000
  297.       End
  298.       Begin MSComctlLib.Slider sldX 
  299.          Height          =   135
  300.          Index           =   2
  301.          Left            =   240
  302.          TabIndex        =   26
  303.          Top             =   3360
  304.          Width           =   2235
  305.          _ExtentX        =   3942
  306.          _ExtentY        =   238
  307.          _Version        =   393216
  308.          Min             =   -20
  309.          Max             =   20
  310.          TickFrequency   =   5
  311.       End
  312.       Begin MSComctlLib.Slider sldY 
  313.          Height          =   135
  314.          Index           =   2
  315.          Left            =   240
  316.          TabIndex        =   27
  317.          Top             =   3600
  318.          Width           =   2235
  319.          _ExtentX        =   3942
  320.          _ExtentY        =   238
  321.          _Version        =   393216
  322.          Min             =   -20
  323.          Max             =   20
  324.          TickFrequency   =   5
  325.       End
  326.       Begin MSComctlLib.Slider sldZ 
  327.          Height          =   135
  328.          Index           =   2
  329.          Left            =   240
  330.          TabIndex        =   28
  331.          Top             =   3840
  332.          Width           =   2235
  333.          _ExtentX        =   3942
  334.          _ExtentY        =   238
  335.          _Version        =   393216
  336.          Min             =   -20
  337.          Max             =   20
  338.          TickFrequency   =   5
  339.       End
  340.       Begin VB.Label lbl 
  341.          BackStyle       =   0  'Transparent
  342.          Caption         =   "Z"
  343.          Height          =   255
  344.          Index           =   20
  345.          Left            =   60
  346.          TabIndex        =   52
  347.          Top             =   3780
  348.          Width           =   195
  349.       End
  350.       Begin VB.Label lbl 
  351.          BackStyle       =   0  'Transparent
  352.          Caption         =   "Y"
  353.          Height          =   255
  354.          Index           =   19
  355.          Left            =   60
  356.          TabIndex        =   51
  357.          Top             =   3600
  358.          Width           =   255
  359.       End
  360.       Begin VB.Label lbl 
  361.          BackStyle       =   0  'Transparent
  362.          Caption         =   "X"
  363.          Height          =   255
  364.          Index           =   18
  365.          Left            =   60
  366.          TabIndex        =   50
  367.          Top             =   3360
  368.          Width           =   195
  369.       End
  370.       Begin VB.Label lbl 
  371.          BackStyle       =   0  'Transparent
  372.          Caption         =   "3D Positioning"
  373.          Height          =   255
  374.          Index           =   17
  375.          Left            =   60
  376.          TabIndex        =   49
  377.          Top             =   3120
  378.          Width           =   2415
  379.       End
  380.       Begin VB.Label lbl 
  381.          BackStyle       =   0  'Transparent
  382.          Caption         =   "Volume (hundredths of a decibel)"
  383.          Height          =   255
  384.          Index           =   16
  385.          Left            =   60
  386.          TabIndex        =   48
  387.          Top             =   2700
  388.          Width           =   2415
  389.       End
  390.       Begin VB.Label lbl 
  391.          BackStyle       =   0  'Transparent
  392.          Caption         =   "Audio Path Settings"
  393.          Height          =   255
  394.          Index           =   5
  395.          Left            =   120
  396.          TabIndex        =   37
  397.          Top             =   2460
  398.          Width           =   2415
  399.       End
  400.       Begin VB.Label lbl 
  401.          BackStyle       =   0  'Transparent
  402.          Caption         =   "Files in Audio Path"
  403.          Height          =   255
  404.          Index           =   2
  405.          Left            =   180
  406.          TabIndex        =   34
  407.          Top             =   240
  408.          Width           =   2415
  409.       End
  410.    End
  411.    Begin VB.Frame fraPath 
  412.       Caption         =   "Audio Path 2 (Secondary)"
  413.       Height          =   4095
  414.       Index           =   1
  415.       Left            =   2640
  416.       TabIndex        =   29
  417.       Top             =   1500
  418.       Width           =   2595
  419.       Begin VB.CheckBox chkLoop 
  420.          Caption         =   "Loop"
  421.          Height          =   195
  422.          Index           =   1
  423.          Left            =   1740
  424.          TabIndex        =   8
  425.          Top             =   1440
  426.          Width           =   735
  427.       End
  428.       Begin MSComctlLib.Slider sldX 
  429.          Height          =   135
  430.          Index           =   1
  431.          Left            =   240
  432.          TabIndex        =   22
  433.          Top             =   3360
  434.          Width           =   2235
  435.          _ExtentX        =   3942
  436.          _ExtentY        =   238
  437.          _Version        =   393216
  438.          Min             =   -20
  439.          Max             =   20
  440.          TickFrequency   =   5
  441.       End
  442.       Begin MSComctlLib.Slider sldVolume 
  443.          Height          =   135
  444.          Index           =   1
  445.          Left            =   60
  446.          TabIndex        =   21
  447.          Top             =   2940
  448.          Width           =   2415
  449.          _ExtentX        =   4260
  450.          _ExtentY        =   238
  451.          _Version        =   393216
  452.          LargeChange     =   500
  453.          SmallChange     =   100
  454.          Min             =   -6000
  455.          Max             =   0
  456.          TickFrequency   =   1000
  457.       End
  458.       Begin VB.CommandButton cmdStop 
  459.          Caption         =   "Stop"
  460.          Height          =   315
  461.          Index           =   1
  462.          Left            =   1680
  463.          TabIndex        =   6
  464.          Top             =   2100
  465.          Width           =   795
  466.       End
  467.       Begin VB.CommandButton cmdPlay 
  468.          Caption         =   "Play"
  469.          Height          =   315
  470.          Index           =   1
  471.          Left            =   1680
  472.          TabIndex        =   7
  473.          Top             =   1740
  474.          Width           =   795
  475.       End
  476.       Begin VB.CommandButton cmdRemove 
  477.          Caption         =   "Remove"
  478.          Height          =   315
  479.          Index           =   1
  480.          Left            =   1680
  481.          TabIndex        =   9
  482.          Top             =   960
  483.          Width           =   795
  484.       End
  485.       Begin VB.CommandButton cmdAdd 
  486.          Caption         =   "Add"
  487.          Height          =   315
  488.          Index           =   1
  489.          Left            =   1680
  490.          TabIndex        =   10
  491.          Top             =   600
  492.          Width           =   795
  493.       End
  494.       Begin VB.ListBox lstPath 
  495.          Height          =   1815
  496.          Index           =   1
  497.          Left            =   120
  498.          TabIndex        =   11
  499.          Top             =   600
  500.          Width           =   1515
  501.       End
  502.       Begin MSComctlLib.Slider sldY 
  503.          Height          =   135
  504.          Index           =   1
  505.          Left            =   240
  506.          TabIndex        =   23
  507.          Top             =   3600
  508.          Width           =   2235
  509.          _ExtentX        =   3942
  510.          _ExtentY        =   238
  511.          _Version        =   393216
  512.          Min             =   -20
  513.          Max             =   20
  514.          TickFrequency   =   5
  515.       End
  516.       Begin MSComctlLib.Slider sldZ 
  517.          Height          =   135
  518.          Index           =   1
  519.          Left            =   240
  520.          TabIndex        =   24
  521.          Top             =   3840
  522.          Width           =   2235
  523.          _ExtentX        =   3942
  524.          _ExtentY        =   238
  525.          _Version        =   393216
  526.          Min             =   -20
  527.          Max             =   20
  528.          TickFrequency   =   5
  529.       End
  530.       Begin VB.Label lbl 
  531.          BackStyle       =   0  'Transparent
  532.          Caption         =   "Z"
  533.          Height          =   255
  534.          Index           =   15
  535.          Left            =   60
  536.          TabIndex        =   47
  537.          Top             =   3780
  538.          Width           =   195
  539.       End
  540.       Begin VB.Label lbl 
  541.          BackStyle       =   0  'Transparent
  542.          Caption         =   "Y"
  543.          Height          =   255
  544.          Index           =   14
  545.          Left            =   60
  546.          TabIndex        =   46
  547.          Top             =   3600
  548.          Width           =   255
  549.       End
  550.       Begin VB.Label lbl 
  551.          BackStyle       =   0  'Transparent
  552.          Caption         =   "X"
  553.          Height          =   255
  554.          Index           =   13
  555.          Left            =   60
  556.          TabIndex        =   45
  557.          Top             =   3360
  558.          Width           =   195
  559.       End
  560.       Begin VB.Label lbl 
  561.          BackStyle       =   0  'Transparent
  562.          Caption         =   "3D Positioning"
  563.          Height          =   255
  564.          Index           =   12
  565.          Left            =   60
  566.          TabIndex        =   44
  567.          Top             =   3120
  568.          Width           =   2415
  569.       End
  570.       Begin VB.Label lbl 
  571.          BackStyle       =   0  'Transparent
  572.          Caption         =   "Volume (hundredths of a decibel)"
  573.          Height          =   255
  574.          Index           =   11
  575.          Left            =   60
  576.          TabIndex        =   43
  577.          Top             =   2700
  578.          Width           =   2415
  579.       End
  580.       Begin VB.Label lbl 
  581.          BackStyle       =   0  'Transparent
  582.          Caption         =   "Audio Path Settings"
  583.          Height          =   255
  584.          Index           =   4
  585.          Left            =   120
  586.          TabIndex        =   36
  587.          Top             =   2460
  588.          Width           =   2415
  589.       End
  590.       Begin VB.Label lbl 
  591.          BackStyle       =   0  'Transparent
  592.          Caption         =   "Files in Audio Path"
  593.          Height          =   255
  594.          Index           =   1
  595.          Left            =   180
  596.          TabIndex        =   33
  597.          Top             =   240
  598.          Width           =   2415
  599.       End
  600.    End
  601.    Begin VB.Label lbl 
  602.       BackStyle       =   0  'Transparent
  603.       Caption         =   "Audio Path Samples"
  604.       Height          =   255
  605.       Index           =   24
  606.       Left            =   600
  607.       TabIndex        =   56
  608.       Top             =   120
  609.       Width           =   2655
  610.    End
  611.    Begin VB.Label lbl 
  612.       BackStyle       =   0  'Transparent
  613.       Caption         =   "Copyright 
  614.  2000, Microsoft Corporation, All Rights Reserved."
  615.       Height          =   195
  616.       Index           =   23
  617.       Left            =   600
  618.       TabIndex        =   55
  619.       Top             =   360
  620.       Width           =   7335
  621.    End
  622.    Begin VB.Image Image1 
  623.       Height          =   480
  624.       Left            =   60
  625.       Picture         =   "frmAudioPath.frx":04CC
  626.       Top             =   120
  627.       Width           =   480
  628.    End
  629.    Begin VB.Label lbl 
  630.       BackStyle       =   0  'Transparent
  631.       Caption         =   $"frmAudioPath.frx":090E
  632.       Height          =   795
  633.       Index           =   22
  634.       Left            =   60
  635.       TabIndex        =   54
  636.       Top             =   600
  637.       Width           =   7875
  638.    End
  639. Attribute VB_Name = "frmAudioPath"
  640. Attribute VB_GlobalNameSpace = False
  641. Attribute VB_Creatable = False
  642. Attribute VB_PredeclaredId = True
  643. Attribute VB_Exposed = False
  644. Option Explicit
  645. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  646. '  Copyright (C) 2000 Microsoft Corporation.  All Rights Reserved.
  647. '  File:       frmAudioPath.frm
  648. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  649. 'Note the actual max files will be 1+ this constant (0 to Max)
  650. Private Const MAX_FILES_PER_AUDIO_PATH As Byte = 4
  651. 'First we need our directx object
  652. Private dx As New DirectX8
  653. 'And we need the audio paths we'll be using
  654. Private dmAudio(0 To 2) As DirectMusicAudioPath8
  655. 'Loader and Performance objects
  656. Private dmLoader As DirectMusicLoader8
  657. Private dmPerformance As DirectMusicPerformance8
  658. 'Each audio path can have up to 5 segments
  659. Private dmSegment(0 To 2, 0 To MAX_FILES_PER_AUDIO_PATH) As DirectMusicSegment8
  660. Private dmState(0 To 2, 0 To MAX_FILES_PER_AUDIO_PATH) As DirectMusicSegmentState8
  661. 'API declare for windows folder
  662. Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
  663. Private Sub InitAudio()
  664.     On Error GoTo FailedInit
  665.     Dim dmAParams As DMUS_AUDIOPARAMS
  666.     Dim lCount As Long
  667.     'First we'll create out loader and performance
  668.     Set dmPerformance = dx.DirectMusicPerformanceCreate
  669.     Set dmLoader = dx.DirectMusicLoaderCreate
  670.     'Now we'll init our audio, and create our audio paths
  671.     dmPerformance.InitAudio Me.hWnd, DMUS_AUDIOF_ALL, dmAParams
  672.     For lCount = 0 To 2
  673.         Set dmAudio(lCount) = dmPerformance.CreateStandardAudioPath(DMUS_APATH_DYNAMIC_3D, 128, True)
  674.         EnablePlayUI lCount, True
  675.     Next
  676.     Exit Sub
  677. FailedInit:
  678.     MsgBox "Could not initialize DirectMusic." & vbCrLf & "This sample will exit.", vbOKOnly Or vbInformation, "Exiting..."
  679.     Unload Me
  680. End Sub
  681. Private Sub Cleanup()
  682.     Dim lCount As Long, lCountInner As Long
  683.     'We need to clean up everything now
  684.     'First unload all of the segments
  685.     For lCount = 0 To 2
  686.         For lCountInner = 0 To MAX_FILES_PER_AUDIO_PATH
  687.             If Not dmSegment(lCount, lCountInner) Is Nothing Then
  688.                 'Stop the segment if it's playing
  689.                 dmPerformance.StopEx dmSegment(lCount, lCountInner), 0, 0
  690.                 'Unload the segment from the audio path
  691.                 dmSegment(lCount, lCountInner).Unload dmAudio(lCount)
  692.                 'Destroy the segment
  693.                 Set dmSegment(lCount, lCountInner) = Nothing
  694.                 'Destroy the state
  695.                 Set dmState(lCount, lCountInner) = Nothing
  696.             End If
  697.         Next
  698.     Next
  699.     For lCount = 0 To 2
  700.         'Destroy the audio path
  701.         Set dmAudio(lCount) = Nothing
  702.     Next
  703.     'Destroy the rest of our objects
  704.     Set dmLoader = Nothing
  705.     If Not (dmPerformance Is Nothing) Then dmPerformance.CloseDown
  706.     Set dmPerformance = Nothing
  707.     Set dx = Nothing
  708. End Sub
  709. Private Sub cmdAdd_Click(Index As Integer)
  710.     Static sCurDir As String
  711.     Static lFilter As Long
  712.     Dim lCount As Long
  713.     'Now we should load a segment
  714.     'First check to see if we already have enough segments
  715.     If Index > 0 Then
  716.         If lstPath(Index).ListCount > MAX_FILES_PER_AUDIO_PATH Then
  717.             MsgBox "You already have " & CStr(MAX_FILES_PER_AUDIO_PATH + 1) & " segments loaded on this audio path.  Please remove one before attempting to load another on this audio path.", vbOKOnly Or vbInformation, "Can't load."
  718.             Exit Sub
  719.         End If
  720.     End If
  721.         
  722.     'Ask them for a file to load
  723.     With cdlOpen
  724.         .flags = cdlOFNFileMustExist Or cdlOFNHideReadOnly
  725.         .FilterIndex = lFilter
  726.         .Filter = "Wave Files (*.wav)|*.wav|Music Files (*.mid;*.rmi)|*.mid;*.rmi|Segment Files (*.sgt)|*.sgt|All Audio Files|*.wav;*.mid;*.rmi;*.sgt|All Files (*.*)|*.*"
  727.         .FileName = vbNullString
  728.         If sCurDir = vbNullString Then
  729.             'Set the init folder to \windows\media if it exists.  If not, set it to the \windows folder
  730.             Dim sWindir As String
  731.             sWindir = Space$(255)
  732.             If GetWindowsDirectory(sWindir, 255) = 0 Then
  733.                 'We couldn't get the windows folder for some reason, use the c:\
  734.                 .InitDir = "C:\"
  735.             Else
  736.                 Dim sMedia As String
  737.                 sWindir = Left$(sWindir, InStr(sWindir, Chr$(0)) - 1)
  738.                 If Right$(sWindir, 1) = "\" Then
  739.                     sMedia = sWindir & "Media"
  740.                 Else
  741.                     sMedia = sWindir & "\Media"
  742.                 End If
  743.                 If Dir$(sMedia, vbDirectory) <> vbNullString Then
  744.                     .InitDir = sMedia
  745.                 Else
  746.                     .InitDir = sWindir
  747.                 End If
  748.             End If
  749.         Else
  750.             .InitDir = sCurDir
  751.         End If
  752.         .ShowOpen   ' Display the Open dialog box
  753.         If .FileName = vbNullString Then Exit Sub 'We didn't click anything exit
  754.         'Save the current information
  755.         sCurDir = GetFolder(.FileName)
  756.         dmLoader.SetSearchDirectory sCurDir
  757.         lFilter = .FilterIndex
  758.         On Local Error GoTo ErrOut
  759.         'Now lets try to create a segment
  760.         If Index > 0 Then
  761.             For lCount = 0 To MAX_FILES_PER_AUDIO_PATH
  762.                 If (dmSegment(Index, lCount) Is Nothing) Then
  763.                     Set dmSegment(Index, lCount) = dmLoader.LoadSegment(.FileName)
  764.                     If (Right$(.FileName, 4) = ".mid") Or (Right$(.FileName, 4) = ".rmi") Or (Right$(.FileName, 5) = ".midi") Then
  765.                         dmSegment(Index, lCount).SetStandardMidiFile
  766.                     End If
  767.                     dmSegment(Index, lCount).Download dmAudio(Index)
  768.                     Exit For
  769.                 End If
  770.             Next
  771.             'Now we can add this file
  772.             lstPath(Index).AddItem .FileName
  773.             lstPath(Index).ItemData(lstPath(Index).ListCount - 1) = ObjPtr(dmSegment(Index, lCount))
  774.         Else
  775.             Set dmSegment(Index, 0) = dmLoader.LoadSegment(.FileName)
  776.             If (Right$(.FileName, 4) = ".mid") Or (Right$(.FileName, 4) = ".rmi") Or (Right$(.FileName, 5) = ".midi") Then
  777.                 dmSegment(Index, 0).SetStandardMidiFile
  778.             End If
  779.             dmSegment(Index, 0).Download dmAudio(Index)
  780.             txtPrimary.Text = .FileName
  781.         End If
  782.         
  783.     End With
  784.     Exit Sub
  785. ErrOut:
  786.     MsgBox "An error occured trying to load this segment.", vbOKOnly Or vbInformation, "Not loaded."
  787. End Sub
  788. Private Sub cmdPlay_Click(Index As Integer)
  789.     Dim lCount As Long
  790.     If Index > 0 Then
  791.         If lstPath(Index).ListCount < 0 Then Exit Sub 'There is nothing to if nothing is select
  792.     ElseIf txtPrimary.Text = vbNullString Then
  793.         Exit Sub
  794.     End If
  795.         
  796.     'We can play our segments
  797.     For lCount = 0 To MAX_FILES_PER_AUDIO_PATH 'Max num of sounds
  798.         If Not dmSegment(Index, lCount) Is Nothing Then 'Nothing to do if there is no segment loaded
  799.             If chkLoop(Index).Value = vbChecked Then
  800.                 dmSegment(Index, lCount).SetRepeats INFINITE
  801.             Else
  802.                 dmSegment(Index, lCount).SetRepeats 0
  803.             End If
  804.             If Index = 0 Then
  805.                 'We must play the segment as default for the primary path
  806.                 Set dmState(Index, lCount) = dmPerformance.PlaySegmentEx(dmSegment(Index, lCount), DMUS_SEGF_DEFAULT, 0, , dmAudio(Index))
  807.             Else
  808.                 'We must play the segment as secondary if we want multiple segments to repeat in the same
  809.                 'audio path.
  810.                 Set dmState(Index, lCount) = dmPerformance.PlaySegmentEx(dmSegment(Index, lCount), DMUS_SEGF_SECONDARY, 0, , dmAudio(Index))
  811.             End If
  812.         End If
  813.     Next
  814.     UpdateVolume Index
  815.     EnablePlayUI Index, False
  816.     cmdStop(Index).SetFocus
  817. End Sub
  818. Private Sub cmdRemove_Click(Index As Integer)
  819.     Dim lCount As Long
  820.     Dim oTempSeg As DirectMusicSegment8
  821.     Dim lPtr As Long
  822.     If lstPath(Index).ListIndex < 0 Then Exit Sub 'There is nothing to if nothing is select
  823.     'Remove this item
  824.     lPtr = lstPath(Index).ItemData(lstPath(Index).ListIndex)
  825.     For lCount = 0 To MAX_FILES_PER_AUDIO_PATH
  826.         If lPtr = ObjPtr(dmSegment(Index, lCount)) Then
  827.             dmPerformance.StopEx dmSegment(Index, lCount), 0, 0
  828.             dmSegment(Index, lCount).Unload dmAudio(Index)
  829.             Set dmSegment(Index, lCount) = Nothing
  830.         End If
  831.     Next
  832.     For lCount = lstPath(Index).ListCount - 1 To 0 Step -1
  833.         If lstPath(Index).ItemData(lCount) = lPtr Then
  834.             lstPath(Index).RemoveItem lCount
  835.         End If
  836.     Next
  837. End Sub
  838. Private Sub cmdStop_Click(Index As Integer)
  839.     Dim lCount As Long
  840.     If Index > 0 Then
  841.         If lstPath(Index).ListCount < 0 Then Exit Sub 'There is nothing to if nothing is select
  842.     ElseIf txtPrimary.Text = vbNullString Then
  843.         Exit Sub
  844.     End If
  845.     'We can stop our segments
  846.     For lCount = 0 To MAX_FILES_PER_AUDIO_PATH
  847.         If Not dmSegment(Index, lCount) Is Nothing Then 'Nothing to do if there is no segment loaded
  848.             dmPerformance.StopEx dmSegment(Index, lCount), 0, 0
  849.             Set dmState(Index, lCount) = Nothing
  850.         End If
  851.     Next
  852.     EnablePlayUI Index, True
  853.     cmdPlay(Index).SetFocus
  854. End Sub
  855. Private Sub Form_Load()
  856.     If App.PrevInstance Then 'We are already running an instance of this, exit
  857.         Dim sSave As String
  858.         'Activate the currently running instance
  859.         sSave = App.Title
  860.         App.Title = App.Title & "... duplicate instance."
  861.         Me.Caption = App.Title & "... duplicate instance."
  862.         AppActivate sSave
  863.         'Get rid of ourselves
  864.         Unload Me
  865.         End
  866.     End If
  867.     InitAudio
  868. End Sub
  869. Private Sub Form_Unload(Cancel As Integer)
  870.     Cleanup
  871. End Sub
  872. Private Function GetFolder(ByVal sFile As String) As String
  873.     Dim lCount As Long
  874.     For lCount = Len(sFile) To 1 Step -1
  875.         If Mid$(sFile, lCount, 1) = "\" Then
  876.             GetFolder = Left$(sFile, lCount)
  877.             Exit Function
  878.         End If
  879.     Next
  880.     GetFolder = vbNullString
  881. End Function
  882. Private Sub lstPath_DblClick(Index As Integer)
  883.     cmdRemove_Click Index
  884. End Sub
  885. Private Sub sldVolume_Click(Index As Integer)
  886.     UpdateVolume Index
  887. End Sub
  888. Private Sub sldVolume_Scroll(Index As Integer)
  889.     UpdateVolume Index
  890. End Sub
  891. Private Sub UpdateVolume(ByVal Index As Integer)
  892.     'Ok , we 're changing, let's get the buffer for this path, and set the 3D position
  893.     Dim dsb As DirectSoundSecondaryBuffer8
  894.     'Get a 3D Buffer
  895.     Set dsb = dmAudio(Index).GetObjectinPath(DMUS_PCHANNEL_ALL, DMUS_PATH_BUFFER, 0, GUID_ALL, 0, IID_DirectSoundSecondaryBuffer)
  896.     'Set the new position of the 3D Buffer (immediately)
  897.     dsb.SetVolume sldVolume(Index).Value
  898.     Set dsb = Nothing
  899. End Sub
  900. Private Sub Update3D(ByVal Index As Integer)
  901.     'Ok, we're changing, let's get the buffer for this path, and set the 3D position
  902.     Dim dsb As DirectSound3DBuffer8
  903.     'Get a 3D Buffer
  904.     Set dsb = dmAudio(Index).GetObjectinPath(DMUS_PCHANNEL_ALL, DMUS_PATH_BUFFER, 0, GUID_ALL, 0, IID_DirectSound3DBuffer)
  905.     'Set the new position of the 3D Buffer (immediately)
  906.     dsb.SetPosition sldX(Index).Value / 5, sldY(Index).Value / 5, sldZ(Index).Value / 5, DS3D_IMMEDIATE
  907.     Set dsb = Nothing
  908. End Sub
  909. Private Sub sldX_Click(Index As Integer)
  910.     Update3D Index
  911. End Sub
  912. Private Sub sldX_Scroll(Index As Integer)
  913.     Update3D Index
  914. End Sub
  915. Private Sub sldY_Click(Index As Integer)
  916.     Update3D Index
  917. End Sub
  918. Private Sub sldY_Scroll(Index As Integer)
  919.     Update3D Index
  920. End Sub
  921. Private Sub sldZ_Click(Index As Integer)
  922.     Update3D Index
  923. End Sub
  924. Private Sub sldZ_Scroll(Index As Integer)
  925.     Update3D Index
  926. End Sub
  927. Public Sub EnablePlayUI(ByVal lIndex As Long, fEnable As Boolean)
  928.     'Enable/Disable the buttons
  929.     If fEnable Then
  930.         chkLoop(lIndex).Enabled = True
  931.         cmdStop(lIndex).Enabled = False
  932.         cmdPlay(lIndex).Enabled = True
  933.         cmdAdd(lIndex).Enabled = True
  934.         If lIndex > 0 Then cmdRemove(lIndex).Enabled = True
  935.     Else
  936.         chkLoop(lIndex).Enabled = False
  937.         cmdStop(lIndex).Enabled = True
  938.         cmdPlay(lIndex).Enabled = False
  939.         cmdAdd(lIndex).Enabled = False
  940.         If lIndex > 0 Then cmdRemove(lIndex).Enabled = False
  941.     End If
  942. End Sub
  943. Private Sub tmrUpdate_Timer()
  944.     Dim lCount As Long
  945.     Dim lIndex As Long
  946.     Dim fEnableIndex As Boolean
  947.     For lIndex = 0 To 2
  948.         fEnableIndex = True
  949.         For lCount = 0 To MAX_FILES_PER_AUDIO_PATH
  950.             If (Not (dmSegment(lIndex, lCount) Is Nothing)) And (Not (dmState(lIndex, lCount) Is Nothing)) Then
  951.                 If dmPerformance.IsPlaying(dmSegment(lIndex, lCount), dmState(lIndex, lCount)) Then
  952.                     fEnableIndex = False
  953.                 End If
  954.             End If
  955.         Next
  956.         EnablePlayUI lIndex, fEnableIndex
  957.     Next
  958. End Sub
  959.