home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / ModBass / vb / frm3d.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2000-01-12  |  16.1 KB  |  463 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#0"; "COMDLG32.OCX"
  3. Begin VB.Form frm3d 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "BASS - 3D Test"
  6.    ClientHeight    =   3555
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   6210
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    ScaleHeight     =   3555
  13.    ScaleWidth      =   6210
  14.    StartUpPosition =   3  'Windows Default
  15.    Begin VB.Frame Frame4 
  16.       Height          =   3495
  17.       Left            =   2640
  18.       TabIndex        =   3
  19.       Top             =   0
  20.       Width           =   3495
  21.       Begin VB.PictureBox picDisplay 
  22.          FillStyle       =   0  'Solid
  23.          Height          =   3135
  24.          Left            =   120
  25.          ScaleHeight     =   205
  26.          ScaleMode       =   3  'Pixel
  27.          ScaleWidth      =   213
  28.          TabIndex        =   4
  29.          Top             =   240
  30.          Width           =   3255
  31.       End
  32.    End
  33.    Begin VB.Frame Frame1 
  34.       Caption         =   "Channels (sample/music)"
  35.       Height          =   2055
  36.       Left            =   120
  37.       TabIndex        =   2
  38.       Top             =   0
  39.       Width           =   2415
  40.       Begin VB.CommandButton cmdStop 
  41.          Caption         =   "Stop"
  42.          Enabled         =   0   'False
  43.          Height          =   300
  44.          Left            =   1320
  45.          TabIndex        =   9
  46.          Top             =   1560
  47.          Width           =   975
  48.       End
  49.       Begin VB.CommandButton cmdPlay 
  50.          Caption         =   "Play"
  51.          Enabled         =   0   'False
  52.          Height          =   300
  53.          Left            =   120
  54.          TabIndex        =   8
  55.          Top             =   1560
  56.          Width           =   975
  57.       End
  58.       Begin VB.CommandButton cmdRemove 
  59.          Caption         =   "Remove"
  60.          Enabled         =   0   'False
  61.          Height          =   300
  62.          Left            =   1320
  63.          TabIndex        =   7
  64.          Top             =   1200
  65.          Width           =   975
  66.       End
  67.       Begin VB.CommandButton cmdAdd 
  68.          Caption         =   "Add ..."
  69.          Height          =   300
  70.          Left            =   120
  71.          TabIndex        =   6
  72.          Top             =   1200
  73.          Width           =   975
  74.       End
  75.       Begin VB.ListBox lstChannels 
  76.          Height          =   840
  77.          ItemData        =   "frm3d.frx":0000
  78.          Left            =   120
  79.          List            =   "frm3d.frx":0002
  80.          TabIndex        =   5
  81.          Top             =   240
  82.          Width           =   2175
  83.       End
  84.    End
  85.    Begin VB.Frame Frame2 
  86.       Caption         =   "Movement"
  87.       ClipControls    =   0   'False
  88.       Height          =   735
  89.       Left            =   120
  90.       TabIndex        =   1
  91.       Top             =   2040
  92.       Width           =   2415
  93.       Begin MSComDlg.CommonDialog DLG 
  94.          Left            =   1680
  95.          Top             =   0
  96.          _ExtentX        =   847
  97.          _ExtentY        =   847
  98.          _Version        =   327681
  99.       End
  100.       Begin VB.OptionButton optDirection 
  101.          Caption         =   "None"
  102.          Height          =   255
  103.          Index           =   4
  104.          Left            =   1680
  105.          TabIndex        =   14
  106.          Top             =   450
  107.          Value           =   -1  'True
  108.          Width           =   700
  109.       End
  110.       Begin VB.OptionButton optDirection 
  111.          Caption         =   "Back"
  112.          Height          =   255
  113.          Index           =   3
  114.          Left            =   120
  115.          TabIndex        =   13
  116.          Top             =   450
  117.          Width           =   735
  118.       End
  119.       Begin VB.OptionButton optDirection 
  120.          Caption         =   "Front"
  121.          Height          =   255
  122.          Index           =   2
  123.          Left            =   1680
  124.          TabIndex        =   12
  125.          Top             =   175
  126.          Width           =   700
  127.       End
  128.       Begin VB.OptionButton optDirection 
  129.          Caption         =   "Right"
  130.          Height          =   255
  131.          Index           =   1
  132.          Left            =   840
  133.          TabIndex        =   11
  134.          Top             =   175
  135.          Width           =   735
  136.       End
  137.       Begin VB.OptionButton optDirection 
  138.          Caption         =   "Left"
  139.          Height          =   255
  140.          Index           =   0
  141.          Left            =   120
  142.          TabIndex        =   10
  143.          Top             =   175
  144.          Width           =   735
  145.       End
  146.       Begin VB.Timer tmr3D 
  147.          Enabled         =   0   'False
  148.          Interval        =   50
  149.          Left            =   2160
  150.          Top             =   0
  151.       End
  152.    End
  153.    Begin VB.Frame Frame3 
  154.       Caption         =   "EAX Environment"
  155.       ClipControls    =   0   'False
  156.       Height          =   735
  157.       Left            =   120
  158.       TabIndex        =   0
  159.       Top             =   2760
  160.       Width           =   2415
  161.       Begin VB.ComboBox cmbEAX 
  162.          BackColor       =   &H00C0C0C0&
  163.          Enabled         =   0   'False
  164.          Height          =   315
  165.          ItemData        =   "frm3d.frx":0004
  166.          Left            =   120
  167.          List            =   "frm3d.frx":0059
  168.          TabIndex        =   15
  169.          Text            =   "Off"
  170.          Top             =   240
  171.          Width           =   2175
  172.       End
  173.    End
  174. Attribute VB_Name = "frm3d"
  175. Attribute VB_GlobalNameSpace = False
  176. Attribute VB_Creatable = False
  177. Attribute VB_PredeclaredId = True
  178. Attribute VB_Exposed = False
  179. '*********************************************************
  180. '* BASS 3D test (rev .1), copyright (c) 1999 Adam Hoult. *
  181. '*********************************************************
  182. Private Type Channel
  183.     Sample As Long          ' Sample Handle (NOTHING if it's a MOD music.
  184.     Channel As Long         ' The Channel
  185.     pos As BASS_3DVECTOR    ' Position
  186.     vel As BASS_3DVECTOR    ' Velocity
  187.     direction As Integer    ' Direction of the channel
  188. End Type
  189. Dim Chans() As Channel      ' Array of channels
  190. Dim NOFChannels As Long     ' Number of Channels
  191. Dim CurrentChannel As Long  ' Current Channel
  192. Const TIMERPER = 50         ' Timer period (ms)
  193. Const MAXDIST = 500         ' maximum distance of the channels (m)
  194. Const SPEED = 5             ' Speed of the channels' movement (m/s)
  195. Const ID_LEFT = 0
  196. Const ID_RIGHT = 1
  197. Const ID_FRONT = 2
  198. Const ID_BACK = 3
  199. Const ID_NONE = 4
  200. Sub ThrowError(Message As String)
  201. 'Display error dialogues
  202. Dim ErrorNum As Long
  203. ErrorNum = BASS_ErrorGetCode
  204. MsgBox Message & vbCrLf & vbCrLf & "Error Code : " & ErrorNum & vbCrLf & BASS_GetErrorDescription(ErrorNum), vbCritical, "Error"
  205. End Sub
  206. Sub Update()
  207. Dim c As Integer, X As Integer, Y As Integer, cx As Integer, cy As Integer
  208. cx = picDisplay.ScaleWidth / 2
  209. cy = picDisplay.ScaleHeight / 2
  210. ' Clear the display
  211. picDisplay.Cls
  212. ' Draw Center Circle
  213. picDisplay.FillColor = RGB(100, 100, 100)
  214. picDisplay.Circle (cx - 4, cy - 4), 4, RGB(0, 0, 0)
  215. For c = 1 To NOFChannels
  216.     ' If the channel is playing, then update it's position
  217.     If BASS_ChannelIsActive(Chans(c).Channel) = BASSTRUE Then
  218.         ' Check if channel has reached the max distance
  219.         If Chans(c).pos.z >= MAXDIST Or Chans(c).pos.z <= -MAXDIST Then Chans(c).vel.z = -Chans(c).vel.z
  220.         If Chans(c).pos.X >= MAXDIST Or Chans(c).pos.X <= -MAXDIST Then Chans(c).vel.X = -Chans(c).vel.X
  221.         ' Update channel position
  222.         Chans(c).pos.z = Chans(c).pos.z + Chans(c).vel.z * TIMERPER / 1000
  223.         Chans(c).pos.X = Chans(c).pos.X + Chans(c).vel.X * TIMERPER / 1000
  224.         If BASS_ChannelSet3DPosition(Chans(c).Channel, Chans(c).pos, Nothing, Chans(c).vel) = BASSFALSE Then ThrowError "Unable to set 3d position"
  225.     End If
  226.     ' Draw the channel position indicator
  227.     X = cx + Int(cx * Chans(c).pos.X / (MAXDIST + 40))
  228.     Y = cy - Int(cy * Chans(c).pos.z / (MAXDIST + 40))
  229.     If CurrentChannel = c Then
  230.         picDisplay.FillColor = RGB(255, 0, 0)
  231.     Else
  232.         picDisplay.FillColor = RGB(150, 0, 0)
  233.     End If
  234.     picDisplay.Circle (X - 4, Y - 4), 4, RGB(0, 0, 0)
  235. Next c
  236. 'Apply 3d changes
  237. BASS_Apply3D
  238. End Sub
  239. Sub UpdateButtons()
  240. ' Update the button states
  241. ' Disable/enable controls depending on NOFChannels
  242. cmdRemove.Enabled = IIf(NOFChannels = 0, False, True)
  243. cmdPlay.Enabled = IIf(NOFChannels = 0, False, True)
  244. cmdStop.Enabled = IIf(NOFChannels = 0, False, True)
  245. For i = 0 To 4
  246.     optDirection(i).Enabled = IIf(NOFChannels = 0, False, True)
  247. Next i
  248. If CurrentChannel > 0 Then
  249.     optDirection(Chans(CurrentChannel).direction).Value = True
  250. End If
  251. End Sub
  252. Private Sub cmdAdd_Click()
  253. On Error Resume Next
  254. ' Change the EAX Environment depending on which is selected
  255. Select Case cmbEAX.ListIndex
  256.     Case 0
  257.         BASS_SetEAXParameters -1, 0, -1, -1
  258.     Case 1
  259.         BASS_SetEAXParametersVB EAX_PRESET_GENERIC
  260.     Case 2
  261.         BASS_SetEAXParametersVB EAX_PRESET_PADDEDCELL
  262.     Case 3
  263.         BASS_SetEAXParametersVB EAX_PRESET_ROOM
  264.     Case 4
  265.         BASS_SetEAXParametersVB EAX_PRESET_BATHROOM
  266.     Case 5
  267.         BASS_SetEAXParametersVB EAX_PRESET_LIVINGROOM
  268.     Case 6
  269.         BASS_SetEAXParametersVB EAX_PRESET_STONEROOM
  270.     Case 7
  271.         BASS_SetEAXParametersVB EAX_PRESET_AUDITORIUM
  272.     Case 8
  273.         BASS_SetEAXParametersVB EAX_PRESET_CONCERTHALL
  274.     Case 9
  275.         BASS_SetEAXParametersVB EAX_PRESET_CAVE
  276.     Case 10
  277.         BASS_SetEAXParametersVB EAX_PRESET_ARENA
  278.     Case 11
  279.         BASS_SetEAXParametersVB EAX_PRESET_HANGAR
  280.     Case 12
  281.         BASS_SetEAXParametersVB EAX_PRESET_CARPETEDHALLWAY
  282.     Case 13
  283.         BASS_SetEAXParametersVB EAX_PRESET_HALLWAY
  284.     Case 14
  285.         BASS_SetEAXParametersVB EAX_PRESET_STONECORRIDOR
  286.     Case 15
  287.         BASS_SetEAXParametersVB EAX_PRESET_ALLEY
  288.     Case 16
  289.         BASS_SetEAXParametersVB EAX_PRESET_FOREST
  290.     Case 17
  291.         BASS_SetEAXParametersVB EAX_PRESET_CITY
  292.     Case 18
  293.         BASS_SetEAXParametersVB EAX_PRESET_MOUNTAINS
  294.     Case 19
  295.         BASS_SetEAXParametersVB EAX_PRESET_QUARRY
  296.     Case 20
  297.         BASS_SetEAXParametersVB EAX_PRESET_PLAIN
  298.     Case 21
  299.         BASS_SetEAXParametersVB EAX_PRESET_PARKINGLOT
  300.     Case 22
  301.         BASS_SetEAXParametersVB EAX_PRESET_SEWERPIPE
  302.     Case 23
  303.         BASS_SetEAXParametersVB EAX_PRESET_UNDERWATER
  304.     Case 24
  305.         BASS_SetEAXParametersVB EAX_PRESET_DRUGGED
  306.     Case 25
  307.         BASS_SetEAXParametersVB EAX_PRESET_DIZZY
  308.     Case 26
  309.         BASS_SetEAXParametersVB EAX_PRESET_PSYCHOTIC
  310. End Select
  311. Dim newchan As Long
  312. DLG.filename = ""
  313. DLG.CancelError = True
  314. DLG.flags = cdlOFNExplorer Or cdlOFNFileMustExist Or cdlOFNHideReadOnly
  315. DLG.Filter = "MOD Music/Sample Files (wav/xm/mod/s3m/it/mtm)|*.wav;*.xm;*.mod;*.s3m;*.it;*.mtm|All Files (*.*)|*.*|"
  316. DLG.ShowOpen
  317. 'if cancel was pressed, exit the procedure
  318. If Err.Number = 32755 Then Exit Sub
  319. ' Load a music from "file" with 3D enabled, and make it loop & use ramping
  320. newchan = BASS_MusicLoad(BASSFALSE, DLG.filename, 0, 0, BASS_MUSIC_RAMP Or BASS_MUSIC_LOOP Or BASS_MUSIC_3D)
  321. If newchan <> 0 Then
  322.     NOFChannels = NOFChannels + 1
  323.     ReDim Preserve Chans(NOFChannels)
  324.     Chans(NOFChannels).Channel = newchan
  325.     Chans(NOFChannels).direction = ID_NONE
  326.     lstChannels.AddItem DLG.filename
  327.     ' Set the min/max distance to 15/1000 meters
  328.     BASS_ChannelSet3DAttributes newchan, -1, 15, 1000, -1, -1, -1
  329.     ' Load a sample from "file" with 3D enabled, and make it loop */
  330.      newchan = BASS_SampleLoad(BASSFALSE, DLG.filename, 0, 0, 1, BASS_SAMPLE_LOOP Or BASS_SAMPLE_3D)
  331.      If newchan <> 0 Then
  332.         Dim sam As BASS_SAMPLE
  333.         NOFChannels = NOFChannels + 1
  334.         ReDim Preserve Chans(NOFChannels)
  335.         Chans(NOFChannels).Sample = newchan
  336.         Chans(NOFChannels).direction = ID_NONE
  337.         lstChannels.AddItem DLG.filename
  338.         'get the info
  339.         BASS_SampleGetInfo newchan, sam
  340.         ' Set the min/max distance to 15/1000 meters
  341.         sam.mindist = 15
  342.         sam.MAXDIST = 1000
  343.         BASS_SampleSetInfo newchan, sam
  344.     Else
  345.         ThrowError "Can't load file"
  346.     End If
  347. End If
  348. End Sub
  349. Private Sub cmdPlay_Click()
  350. 'Play the select sample/music
  351. If Chans(CurrentChannel).Sample > 0 Then
  352.     If Chans(CurrentChannel).Channel = 0 Then
  353.         Chans(CurrentChannel).Channel = BASS_SamplePlay3D(Chans(CurrentChannel).Sample, Chans(CurrentChannel).pos, Nothing, Chans(CurrentChannel).vel)
  354.     End If
  355.     BASS_MusicPlay Chans(CurrentChannel).Channel
  356. End If
  357. End Sub
  358. Private Sub cmdRemove_Click()
  359.     If Chans(CurrentChannel).Sample > 0 Then
  360.         BASS_SampleFree Chans(CurrentChannel).Sample
  361.     Else
  362.         BASS_MusicFree Chans(CurrentChannel).Channel
  363.     End If
  364.     'remove the item from the array
  365.     Dim TempChans() As Channel, Counter As Integer
  366.     ReDim TempChans(NOFChannels)
  367.     Counter = 0
  368.     For i = 1 To NOFChannels
  369.         If i <> CurrentChannel Then
  370.             Counter = Counter + 1
  371.             TempChans(Counter) = Chans(i)
  372.         End If
  373.     Next i
  374.     NOFChannels = NOFChannels - 1
  375.     ReDim Chans(NOFChannels)
  376.     For i = 1 To NOFChannels
  377.         Chans(i) = TempChans(i)
  378.     Next i
  379.     Erase TempChans
  380.     lstChannels.RemoveItem lstChannels.ListIndex
  381.     CurrentChannel = 0
  382.     UpdateButtons
  383. End Sub
  384. Private Sub cmdStop_Click()
  385. 'stop playing music/sample
  386. BASS_ChannelStop Chans(CurrentChannel).Channel
  387. If Chans(CurrentChannel).Sample > 0 Then Chans(CurrentChannel).Channel = 0
  388. End Sub
  389. Private Sub Form_Load()
  390. cmbEAX.ListIndex = 0
  391. DLG.InitDir = App.Path
  392. ' Check that BASS 0.8 was loaded
  393. If BASS_GetStringVersion <> "0.8" Then
  394.     ThrowError "BASS version 0.8 was not loaded"
  395. End If
  396. ' Initialize output device - default device, 44100hz, stereo, 16 bits, with 3D funtionality
  397. If BASS_Init(-1, 44100, BASS_DEVICE_3D, frm3d.hWnd) = BASSFALSE Then ThrowError "Can't initialize output device"
  398. ' Use meters as distance unit, 2x real world rolloff, real doppler effect
  399. BASS_Set3DFactors 1, 2, 1
  400. 'Turn EAX off (volume=0.0), if error then EAX is not supported
  401. If BASS_SetEAXParameters(-1, 0, -1, -1) = BASSFALSE Then
  402.     cmbEAX.Enabled = False
  403.     cmbEAX.Enabled = True
  404. End If
  405. ' Start digital output
  406. BASS_Start
  407. UpdateButtons
  408. tmr3D.Enabled = True
  409. End Sub
  410. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  411. ' Stop digital output.
  412. BASS_Stop
  413. BASS_Free
  414. Erase Chans
  415. End Sub
  416. Private Sub lstChannels_Click()
  417.     ' Change the selected channel
  418.     CurrentChannel = lstChannels.ListIndex + 1
  419.     If chan < 0 Then chan = 0
  420.     UpdateButtons
  421. End Sub
  422. Private Sub optDirection_Click(Index As Integer)
  423. Select Case Index
  424.     Case ID_LEFT
  425.         Chans(CurrentChannel).direction = ID_LEFT
  426.         ' Make the channel move past the left of you
  427.         ' Set speed in m/s
  428.         Chans(CurrentChannel).vel.z = SPEED * 1000 / TIMERPER
  429.         Chans(CurrentChannel).vel.X = 0
  430.         ' Set positon to the left
  431.         Chans(CurrentChannel).pos.X = -20
  432.     Case ID_RIGHT
  433.         Chans(CurrentChannel).direction = ID_RIGHT
  434.         ' Make the channel move past the Right of you
  435.         Chans(CurrentChannel).vel.z = SPEED * 1000 / TIMERPER
  436.         Chans(CurrentChannel).vel.X = 0
  437.         ' Set positon to the Right
  438.         Chans(CurrentChannel).pos.X = 20
  439.     Case ID_FRONT
  440.         Chans(CurrentChannel).direction = ID_FRONT
  441.         ' Make the channel move past the front of you
  442.         Chans(CurrentChannel).vel.X = SPEED * 1000 / TIMERPER
  443.         Chans(CurrentChannel).vel.z = 0
  444.         ' Set positon to the front
  445.         Chans(CurrentChannel).pos.z = 20
  446.     Case ID_BACK
  447.         Chans(CurrentChannel).direction = ID_BACK
  448.         ' Make the channel move past the back of you
  449.         Chans(CurrentChannel).vel.X = SPEED * 1000 / TIMERPER
  450.         Chans(CurrentChannel).vel.z = 0
  451.         ' Set positon to the back
  452.         Chans(CurrentChannel).pos.z = -20
  453.     Case ID_NONE
  454.         Chans(CurrentChannel).direction = ID_NONE
  455.         ' Make the channel stop moving
  456.         Chans(CurrentChannel).vel.z = 0
  457.         Chans(CurrentChannel).vel.X = 0
  458. End Select
  459. End Sub
  460. Private Sub tmr3D_Timer()
  461.     Update
  462. End Sub
  463.