home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 May / PCFMay2001.iso / Xenon / ModBass / vb / frmMain.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2000-01-23  |  15.5 KB  |  479 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#0"; "COMDLG32.OCX"
  3. Begin VB.Form frmMain 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "BASS - Simple Test"
  6.    ClientHeight    =   3675
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   5310
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    ScaleHeight     =   3675
  13.    ScaleWidth      =   5310
  14.    StartUpPosition =   3  'Windows Default
  15.    Begin VB.CommandButton cmdResumeAll 
  16.       Caption         =   "Resume"
  17.       Height          =   375
  18.       Left            =   1680
  19.       TabIndex        =   30
  20.       Top             =   3240
  21.       Width           =   855
  22.    End
  23.    Begin VB.CommandButton cmdStopAll 
  24.       Caption         =   "Stop Everything"
  25.       Height          =   375
  26.       Left            =   120
  27.       TabIndex        =   29
  28.       Top             =   3240
  29.       Width           =   1455
  30.    End
  31.    Begin VB.Timer tmrBass 
  32.       Enabled         =   0   'False
  33.       Interval        =   100
  34.       Left            =   2640
  35.       Top             =   2040
  36.    End
  37.    Begin VB.Frame Frame4 
  38.       Caption         =   "CD"
  39.       Height          =   975
  40.       Left            =   2640
  41.       TabIndex        =   17
  42.       Top             =   2160
  43.       Width           =   2535
  44.       Begin VB.CheckBox chkCDInDrive 
  45.          Caption         =   "CD?"
  46.          Enabled         =   0   'False
  47.          Height          =   315
  48.          Left            =   120
  49.          TabIndex        =   24
  50.          Top             =   600
  51.          Width           =   615
  52.       End
  53.       Begin VB.CommandButton cmdCDStop 
  54.          Caption         =   "Stop"
  55.          Height          =   300
  56.          Left            =   800
  57.          TabIndex        =   23
  58.          Top             =   600
  59.          Width           =   735
  60.       End
  61.       Begin VB.CommandButton cmdCDResume 
  62.          Caption         =   "Resume"
  63.          Height          =   300
  64.          Left            =   1560
  65.          TabIndex        =   22
  66.          Top             =   600
  67.          Width           =   855
  68.       End
  69.       Begin VB.CommandButton cmdCDPlay 
  70.          Caption         =   "Play"
  71.          Height          =   300
  72.          Left            =   1560
  73.          TabIndex        =   21
  74.          Top             =   240
  75.          Width           =   855
  76.       End
  77.       Begin VB.TextBox txtTrack 
  78.          Height          =   285
  79.          Left            =   600
  80.          TabIndex        =   19
  81.          Text            =   "1"
  82.          Top             =   240
  83.          Width           =   255
  84.       End
  85.       Begin VB.Label lblTime 
  86.          AutoSize        =   -1  'True
  87.          Caption         =   "0:00"
  88.          Height          =   195
  89.          Left            =   960
  90.          TabIndex        =   20
  91.          Top             =   275
  92.          Width           =   315
  93.       End
  94.       Begin VB.Label Label1 
  95.          AutoSize        =   -1  'True
  96.          Caption         =   "Track"
  97.          Height          =   195
  98.          Left            =   120
  99.          TabIndex        =   18
  100.          Top             =   275
  101.          Width           =   420
  102.       End
  103.    End
  104.    Begin VB.Frame Frame3 
  105.       Caption         =   "Stream"
  106.       Height          =   975
  107.       Left            =   120
  108.       TabIndex        =   12
  109.       Top             =   2160
  110.       Width           =   2415
  111.       Begin VB.CommandButton cmdStreamStop 
  112.          Caption         =   "Stop"
  113.          Height          =   300
  114.          Left            =   1560
  115.          TabIndex        =   16
  116.          Top             =   600
  117.          Width           =   735
  118.       End
  119.       Begin VB.CommandButton cmdStreamPlay 
  120.          Caption         =   "Play"
  121.          Height          =   300
  122.          Left            =   840
  123.          TabIndex        =   15
  124.          Top             =   600
  125.          Width           =   735
  126.       End
  127.       Begin VB.CommandButton cmdStreamNew 
  128.          Caption         =   "New ..."
  129.          Height          =   300
  130.          Left            =   120
  131.          TabIndex        =   14
  132.          Top             =   600
  133.          Width           =   735
  134.       End
  135.       Begin VB.TextBox txtStream 
  136.          BackColor       =   &H80000000&
  137.          Height          =   285
  138.          Left            =   120
  139.          Locked          =   -1  'True
  140.          TabIndex        =   13
  141.          Top             =   240
  142.          Width           =   2175
  143.       End
  144.    End
  145.    Begin VB.Frame Frame2 
  146.       Caption         =   "Sample"
  147.       Height          =   2055
  148.       Left            =   2640
  149.       TabIndex        =   7
  150.       Top             =   0
  151.       Width           =   2535
  152.       Begin VB.CommandButton cmdSampleRemove 
  153.          Caption         =   "Remove"
  154.          Height          =   375
  155.          Left            =   1320
  156.          TabIndex        =   11
  157.          Top             =   1560
  158.          Width           =   1095
  159.       End
  160.       Begin VB.CommandButton cmdSampleAdd 
  161.          Caption         =   "Add ..."
  162.          Height          =   375
  163.          Left            =   120
  164.          TabIndex        =   10
  165.          Top             =   1560
  166.          Width           =   1095
  167.       End
  168.       Begin VB.ListBox lstSamples 
  169.          Height          =   840
  170.          ItemData        =   "frmMain.frx":0000
  171.          Left            =   120
  172.          List            =   "frmMain.frx":0002
  173.          TabIndex        =   9
  174.          Top             =   240
  175.          Width           =   2295
  176.       End
  177.       Begin VB.CommandButton cmdSamplePlay 
  178.          Caption         =   "Play"
  179.          Height          =   375
  180.          Left            =   120
  181.          TabIndex        =   8
  182.          Top             =   1200
  183.          Width           =   2295
  184.       End
  185.    End
  186.    Begin MSComDlg.CommonDialog DLG 
  187.       Left            =   2160
  188.       Top             =   1920
  189.       _ExtentX        =   847
  190.       _ExtentY        =   847
  191.       _Version        =   327681
  192.    End
  193.    Begin VB.Frame Frame1 
  194.       Caption         =   "Music"
  195.       Height          =   2055
  196.       Left            =   120
  197.       TabIndex        =   0
  198.       Top             =   0
  199.       Width           =   2415
  200.       Begin VB.CommandButton cmdMusicRemove 
  201.          Caption         =   "Remove"
  202.          Height          =   375
  203.          Left            =   1200
  204.          TabIndex        =   6
  205.          Top             =   1560
  206.          Width           =   1095
  207.       End
  208.       Begin VB.CommandButton cmdMusicAdd 
  209.          Caption         =   "Add ..."
  210.          Height          =   375
  211.          Left            =   120
  212.          TabIndex        =   5
  213.          Top             =   1560
  214.          Width           =   1095
  215.       End
  216.       Begin VB.CommandButton cmdMusicRestart 
  217.          Caption         =   "Restart"
  218.          Height          =   375
  219.          Left            =   1560
  220.          TabIndex        =   4
  221.          Top             =   1200
  222.          Width           =   735
  223.       End
  224.       Begin VB.CommandButton cmdMusicStop 
  225.          Caption         =   "Stop"
  226.          Height          =   375
  227.          Left            =   840
  228.          TabIndex        =   3
  229.          Top             =   1200
  230.          Width           =   735
  231.       End
  232.       Begin VB.CommandButton cmdMusicPlay 
  233.          Caption         =   "Play"
  234.          Height          =   375
  235.          Left            =   120
  236.          TabIndex        =   2
  237.          Top             =   1200
  238.          Width           =   735
  239.       End
  240.       Begin VB.ListBox lstMusic 
  241.          Height          =   840
  242.          ItemData        =   "frmMain.frx":0004
  243.          Left            =   120
  244.          List            =   "frmMain.frx":0006
  245.          TabIndex        =   1
  246.          Top             =   240
  247.          Width           =   2175
  248.       End
  249.    End
  250.    Begin VB.Label Label3 
  251.       AutoSize        =   -1  'True
  252.       BackStyle       =   0  'Transparent
  253.       Caption         =   "Volume"
  254.       Height          =   195
  255.       Left            =   4560
  256.       TabIndex        =   28
  257.       Top             =   3240
  258.       Width           =   525
  259.    End
  260.    Begin VB.Label Label2 
  261.       AutoSize        =   -1  'True
  262.       BackStyle       =   0  'Transparent
  263.       Caption         =   "CPU"
  264.       Height          =   195
  265.       Left            =   3960
  266.       TabIndex        =   27
  267.       Top             =   3240
  268.       Width           =   330
  269.    End
  270.    Begin VB.Label lblVolume 
  271.       AutoSize        =   -1  'True
  272.       Caption         =   "100"
  273.       Height          =   195
  274.       Left            =   4680
  275.       TabIndex        =   26
  276.       Top             =   3450
  277.       Width           =   270
  278.    End
  279.    Begin VB.Label lblCPU 
  280.       Alignment       =   2  'Center
  281.       AutoSize        =   -1  'True
  282.       Caption         =   "0"
  283.       Height          =   195
  284.       Left            =   4080
  285.       TabIndex        =   25
  286.       Top             =   3450
  287.       Width           =   90
  288.    End
  289. Attribute VB_Name = "frmMain"
  290. Attribute VB_GlobalNameSpace = False
  291. Attribute VB_Creatable = False
  292. Attribute VB_PredeclaredId = True
  293. Attribute VB_Exposed = False
  294. '*************************************************************
  295. '* BASS Simple test (rev .1), copyright (c) 1999 Adam Hoult. *
  296. '*************************************************************
  297. Dim STRM As Long          ' Stream Handle
  298. Dim CDPlaying As Boolean ' Is the CD Playing ??
  299. Private Sub cmdCDPlay_Click()
  300. 'Play the specified CD Track
  301. If BASS_CDPlay(Val(txtTrack.Text), BASSTRUE, BASSFALSE) = BASSFALSE Then ThrowError "Can't play CD" Else CDPlaying = True
  302. End Sub
  303. Private Sub cmdCDResume_Click()
  304. ' Resume CD
  305. If BASS_ChannelResume(CDCHANNEL) = True Then CDPlaying = True
  306. End Sub
  307. Private Sub cmdCDStop_Click()
  308. ' Pause CD
  309. BASS_ChannelPause CDCHANNEL
  310. CDPlaying = False
  311. End Sub
  312. Private Sub cmdMusicAdd_Click()
  313. On Error Resume Next
  314. DLG.filename = ""
  315. DLG.CancelError = True
  316. DLG.flags = cdlOFNExplorer Or cdlOFNFileMustExist Or cdlOFNHideReadOnly
  317. DLG.Filter = "MOD Music Files (xm/mod/s3m/it/mtm)|*.xm;*.mod;*.s3m;*.it;*.mtm|All Files (*.*)|*.*|"
  318. DLG.ShowOpen
  319. 'if cancel was pressed, exit the procedure
  320. If Err.Number = 32755 Then Exit Sub
  321. Dim ModHandle As Long
  322. ModHandle = BASS_MusicLoad(BASSFALSE, DLG.filename, 0, 0, BASS_MUSIC_RAMP)
  323. lstMusic.AddItem Trim(Str(lstMusic.ListCount + 1)) & ". " & BASS_MusicGetName(ModHandle)
  324. If ModHandle = 0 Then
  325.     ThrowError "Can't Load Music"
  326.     lstMusic.ItemData(lstMusic.ListCount - 1) = ModHandle
  327. End If
  328. End Sub
  329. Private Sub cmdMusicPlay_Click()
  330. On Error GoTo E_Out
  331. 'play the selected song.
  332. If BASS_MusicPlay(lstMusic.ItemData(lstMusic.ListIndex)) = BASSFALSE Then ThrowError "Can't play music"
  333. E_Out:
  334. End Sub
  335. Private Sub cmdMusicRemove_Click()
  336. On Error GoTo E_Out
  337. ' Free the selected mod resource
  338. ' Remove the selected list
  339. BASS_MusicFree lstMusic.ItemData(lstMusic.ListIndex)
  340. lstMusic.RemoveItem lstMusic.ListIndex
  341. E_Out:
  342. End Sub
  343. Private Sub cmdMusicRestart_Click()
  344. On Error GoTo E_Out
  345. ' Play the music from the start
  346. BASS_MusicPlayEx lstMusic.ItemData(lstMusic.ListIndex), 0, -1, BASSTRUE
  347. E_Out:
  348. End Sub
  349. Private Sub cmdMusicStop_Click()
  350. On Error GoTo E_Out
  351. ' Stop the currently selected music.
  352. If BASS_ChannelStop(lstMusic.ItemData(lstMusic.ListIndex)) = BASSFALSE Then ThrowError "Can't stop Music"
  353. E_Out:
  354. End Sub
  355. Private Sub cmdResumeAll_Click()
  356. ' Resume digital output and CD
  357. If CDPlaying = True Then BASS_ChannelResume CDCHANNEL
  358. BASS_Start
  359. End Sub
  360. Private Sub cmdSampleAdd_Click()
  361. On Error Resume Next
  362. DLG.filename = ""
  363. DLG.CancelError = True
  364. DLG.flags = cdlOFNExplorer Or cdlOFNFileMustExist Or cdlOFNHideReadOnly
  365. DLG.Filter = "WAVE sample files (*.wav)|*.wav|All Files (*.*)|*.*|"
  366. DLG.ShowOpen
  367. 'if cancel was pressed, exit the procedure
  368. If Err.Number = 32755 Then Exit Sub
  369. Dim SampleHandle As Long
  370. lstSamples.AddItem DLG.filename
  371. SampleHandle = BASS_SampleLoad(BASSFALSE, DLG.filename, 0, 0, 3, BASS_SAMPLE_OVER_POS)
  372. If SampleHandle = 0 Then
  373.     ThrowError "Can't Load Sample"
  374.     lstSamples.ItemData(lstSamples.ListCount - 1) = SampleHandle
  375. End If
  376. End Sub
  377. Private Sub cmdSamplePlay_Click()
  378. On Error GoTo E_Out
  379. 'play the selected sample.
  380. If BASS_SamplePlayEx(lstSamples.ItemData(lstSamples.ListIndex), 0, -1, 50, Int((201 * Rnd) - 100), BASSFALSE) = BASSFALSE Then ThrowError "Can't play sample"
  381. E_Out:
  382. End Sub
  383. Private Sub cmdSampleRemove_Click()
  384. On Error GoTo E_Out
  385. ' Free the selected sample resource
  386. ' Remove the selected list item
  387. BASS_SampleFree lstSamples.ItemData(lstSamples.ListIndex)
  388. lstSamples.RemoveItem lstSamples.ListIndex
  389. E_Out:
  390. End Sub
  391. Private Sub cmdStopAll_Click()
  392. ' Pause digital output and CD
  393. BASS_Pause
  394. BASS_ChannelPause CDCHANNEL
  395. End Sub
  396. Private Sub cmdStreamNew_Click()
  397. On Error Resume Next
  398. DLG.filename = ""
  399. DLG.CancelError = True
  400. DLG.flags = cdlOFNExplorer Or cdlOFNFileMustExist Or cdlOFNHideReadOnly
  401. DLG.Filter = "Streamable Files (MP3/Wav)|*.mp3; *.wav|All Files (*.*)|*.*|"
  402. DLG.ShowOpen
  403. 'if cancel was pressed, exit the procedure
  404. If Err.Number = 32755 Then Exit Sub
  405. txtStream.Text = DLG.filename
  406. ' Free old stream (if any) and create new one
  407. BASS_StreamFree STRM
  408. Dim StreamHandle As Long
  409. StreamHandle = BASS_StreamCreateFile(BASSFALSE, DLG.filename, 0, 0, 0)
  410. If StreamHandle = 0 Then
  411.     ThrowError "Can't create stream"
  412.     STRM = StreamHandle
  413. End If
  414. End Sub
  415. Private Sub cmdStreamPlay_Click()
  416. 'Play stream, not flushed
  417. If BASS_StreamPlay(STRM, BASSFALSE, 0) = BASSFALSE Then ThrowError "Can't play stream"
  418. End Sub
  419. Private Sub cmdStreamStop_Click()
  420. ' Stop the stream
  421. BASS_ChannelStop STRM
  422. End Sub
  423. Private Sub Form_Load()
  424. ' Check that BASS 0.8 was loaded
  425. If BASS_GetStringVersion <> "0.8" Then ThrowError "BASS version 0.8 was not loaded": End
  426. ' Initialize digital sound - default device, 44100hz, stereo, 16 bits
  427. If BASS_Init(-1, 44100, 0, Me.hWnd) = BASSFALSE Then ThrowError "Can't initialize digital sound system": End
  428. ' Initialize CD
  429. If BASS_CDInit(Nothing) = BASSFALSE Then ThrowError "Can't initialize CD system"
  430. ' Start digital output
  431. If BASS_Start = BASSFALSE Then ThrowError "Can't start digital output"
  432. 'Set the initial directory to the EXE directory
  433. DLG.InitDir = App.Path
  434. 'Start the timer
  435. tmrBass.Enabled = True
  436. End Sub
  437. Sub ThrowError(Message As String)
  438. 'Display error dialogues
  439. Dim ErrorNum As Long
  440. ErrorNum = BASS_ErrorGetCode
  441. MsgBox Message & vbCrLf & vbCrLf & "Error Code : " & ErrorNum & vbCrLf & BASS_GetErrorDescription(ErrorNum), vbCritical, "Error"
  442. End Sub
  443. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  444. ' Stop digital output
  445. BASS_Stop
  446. ' Free the stream
  447. BASS_StreamFree STRM
  448. ' It's not actually necessary to free the musics and samples
  449. ' because they are automatically freed by BASS_Free
  450. ' Free musics
  451. For i = 0 To lstMusic.ListCount - 1
  452.     BASS_MusicFree lstMusic.ItemData(i)
  453. Next i
  454. ' Free samples
  455. For i = 0 To lstSamples.ListCount - 1
  456.     BASS_SampleFree lstSamples.ItemData(i)
  457. Next i
  458. ' Close digital sound system
  459. BASS_Free
  460. ' Close CD system
  461. BASS_CDFree
  462. End Sub
  463. Private Sub tmrBass_Timer()
  464. Dim p As Long
  465. 'Main timer, to update all info needed.
  466. ' update the CD status
  467. chkCDInDrive.Value = BASS_CDInDrive
  468. If BASS_CDInDrive = 1 Then
  469.     p = BASS_ChannelGetPosition(CDCHANNEL)
  470.     lblTime.Caption = Int(p / 60000) & ":" & Right("00" & Int((p / 1000)), 2)
  471.     Debug.Print Int((p / 1000))
  472.     lblTime.Caption = "0:00"
  473. End If
  474. ' update the CPU usage % display
  475. lblCPU.Caption = CInt(BASS_GetCPU)
  476. ' update the volume level display
  477. lblVolume.Caption = BASS_GetVolume
  478. End Sub
  479.