home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 November / CDVD1105.ISO / Software / Freeware / programare / bass / vb / Memory / frmMemory.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2005-09-22  |  8.7 KB  |  239 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
  3. Begin VB.Form frmMemory 
  4.    BorderStyle     =   3  'Fixed Dialog
  5.    Caption         =   "(: JOBnik! :) - Playing from Memory"
  6.    ClientHeight    =   3300
  7.    ClientLeft      =   45
  8.    ClientTop       =   360
  9.    ClientWidth     =   4215
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   3300
  14.    ScaleWidth      =   4215
  15.    StartUpPosition =   2  'CenterScreen
  16.    Begin VB.CheckBox chkSYNC 
  17.       Caption         =   "SYNC @ END {will show an API MessageBox}"
  18.       Height          =   255
  19.       Left            =   120
  20.       TabIndex        =   6
  21.       Top             =   3000
  22.       Width           =   3975
  23.    End
  24.    Begin VB.Frame Frame1 
  25.       Height          =   3015
  26.       Left            =   0
  27.       TabIndex        =   0
  28.       Top             =   -80
  29.       Width           =   4215
  30.       Begin VB.CommandButton cmdOpenPlay 
  31.          Caption         =   "Click here to open a file && play it"
  32.          Height          =   495
  33.          Left            =   120
  34.          TabIndex        =   1
  35.          Top             =   1440
  36.          Width           =   3975
  37.       End
  38.       Begin VB.Timer tmrBASS 
  39.          Enabled         =   0   'False
  40.          Interval        =   100
  41.          Left            =   2880
  42.          Top             =   840
  43.       End
  44.       Begin MSComDlg.CommonDialog cmd 
  45.          Left            =   3480
  46.          Top             =   840
  47.          _ExtentX        =   847
  48.          _ExtentY        =   847
  49.          _Version        =   393216
  50.       End
  51.       Begin VB.Label lblBitsPS 
  52.          AutoSize        =   -1  'True
  53.          Caption         =   "Kbp/s:"
  54.          Height          =   195
  55.          Left            =   120
  56.          TabIndex        =   10
  57.          Top             =   2760
  58.          Width           =   480
  59.       End
  60.       Begin VB.Label lblBPS 
  61.          AutoSize        =   -1  'True
  62.          Caption         =   "Bytes/s:"
  63.          Height          =   195
  64.          Left            =   120
  65.          TabIndex        =   9
  66.          Top             =   2520
  67.          Width           =   585
  68.       End
  69.       Begin VB.Label lblFreq 
  70.          AutoSize        =   -1  'True
  71.          Caption         =   "Frequency:"
  72.          Height          =   195
  73.          Left            =   120
  74.          TabIndex        =   8
  75.          Top             =   2280
  76.          Width           =   795
  77.       End
  78.       Begin VB.Label lblDXVer 
  79.          AutoSize        =   -1  'True
  80.          Caption         =   "DX Version:"
  81.          Height          =   195
  82.          Left            =   120
  83.          TabIndex        =   7
  84.          Top             =   2040
  85.          Width           =   840
  86.       End
  87.       Begin VB.Label lblFilePath 
  88.          AutoSize        =   -1  'True
  89.          Caption         =   "File:"
  90.          Height          =   195
  91.          Left            =   120
  92.          TabIndex        =   5
  93.          Top             =   240
  94.          Width           =   285
  95.       End
  96.       Begin VB.Label lblDur 
  97.          AutoSize        =   -1  'True
  98.          Caption         =   "Total Duration: 0.0 seconds / 00:00:00"
  99.          Height          =   195
  100.          Left            =   120
  101.          TabIndex        =   4
  102.          Top             =   600
  103.          Width           =   2760
  104.       End
  105.       Begin VB.Label lblPos 
  106.          AutoSize        =   -1  'True
  107.          Caption         =   "Playing Position: 0.0 seconds"
  108.          Height          =   195
  109.          Left            =   120
  110.          TabIndex        =   3
  111.          Top             =   840
  112.          Width           =   2070
  113.       End
  114.       Begin VB.Label lblMins 
  115.          AutoSize        =   -1  'True
  116.          Caption         =   "Time: 00:00:00"
  117.          Height          =   195
  118.          Left            =   120
  119.          TabIndex        =   2
  120.          Top             =   1080
  121.          Width           =   1065
  122.       End
  123.    End
  124. Attribute VB_Name = "frmMemory"
  125. Attribute VB_GlobalNameSpace = False
  126. Attribute VB_Creatable = False
  127. Attribute VB_PredeclaredId = True
  128. Attribute VB_Exposed = False
  129. '///////////////////////////////////////////////////////////////////////////////
  130. ' frmMemory.frm - Copyright (c) 2001-2005 (: JOBnik! :) [Arthur Aminov, ISRAEL]
  131. '                                                       [http://www.jobnik.org]
  132. '                                                       [  jobnik@jobnik.org  ]
  133. ' Other sources: CBASS_TIME.cls & SYNCtest.bas
  134. ' (: JOBnik! :) - Playing from Memory
  135. ' * Updates:
  136. '    . Now uses only VB functions without any Memory APIs
  137. '    . Threading
  138. ' * Based on 'C' example by Ian Luck
  139. '///////////////////////////////////////////////////////////////////////////////
  140. Option Explicit
  141. Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
  142. Private Sub Form_Initialize()
  143.     'change and set the current path
  144.     'so VB won't ever tell you that bass.dll isn't found
  145.     ChDrive App.Path
  146.     ChDir App.Path
  147.     'check if "bass.dll" is exists
  148.     If (Not FileExists(RPP(App.Path) & "bass.dll")) Then
  149.         Call MsgBox("BASS.DLL does not exists", vbCritical, "BASS.DLL")
  150.         End
  151.     End If
  152.     'Check that BASS 2.2 was loaded
  153.     If (BASS_GetVersion <> MakeLong(2, 2)) Then
  154.         Call MsgBox("BASS version 2.2 was not loaded", vbCritical, "Incorrect BASS.DLL")
  155.         End
  156.     End If
  157.     'Start digital output
  158.     If (BASS_Init(-1, 44100, 0, Me.hwnd, 0) = 0) Then
  159.         Call Error_("Couldn't Initialize Digital Output")
  160.         End
  161.     End If
  162.     Set bassTime = New cbass_time
  163.     lblDXVer.Caption = "DX Version: " & bassTime.GetDXver
  164.     cthread = 0
  165. End Sub
  166. 'this function will check if you're running in IDE or EXE modes
  167. 'VB will crash if you're closing the app while (cthread<>0) in IDE,
  168. 'but won't crash if in EXE mode
  169. Public Function isIDEmode() As Boolean
  170.     Dim sFileName As String, lCount As Long
  171.     sFileName = String(255, 0)
  172.     lCount = GetModuleFileName(App.hInstance, sFileName, 255)
  173.     sFileName = UCase(GetFileName(Mid(sFileName, 1, lCount)))
  174.     isIDEmode = (sFileName = "VB6.EXE")
  175. End Function
  176. Private Sub Form_Unload(Cancel As Integer)
  177.     If (isIDEmode And cthread) Then
  178.         'IDE Version
  179.         Cancel = True   'disable closing app to avoid crash
  180.     Else
  181.         'Compiled Version or (cthread = 0) close app is available
  182.         'free it all
  183.         Call BASS_Free
  184.         Erase DataStore()
  185.         'Set bassTime = Nothing
  186.         End
  187.     End If
  188. End Sub
  189. Private Sub cmdOpenPlay_Click()
  190.     On Local Error Resume Next          'if Cancel was pressed
  191.     If (cthread) Then   'already creating
  192.         Call Beep
  193.     Else
  194.         cmd.FileName = ""
  195.         cmd.CancelError = True
  196.         cmd.flags = cdlOFNExplorer Or cdlOFNFileMustExist Or cdlOFNHideReadOnly
  197.         cmd.Filter = "playable files|*.mo3;*.xm;*.mod;*.s3m;*.it;*.mtm;*.mp1;*.mp2;*.mp3;*.wav;*.ogg;*.aif|All files|*.*"
  198.         cmd.ShowOpen
  199.         'if cancel was pressed, exit sub
  200.         If Err.Number = 32755 Then Exit Sub
  201.         tmrBASS.Enabled = False
  202.         lblFilePath.Caption = "File: " & GetFileName(cmd.FileName)
  203.         cmdOpenPlay.Caption = "Loading file..."
  204.         'make a new thread, copy file into memory and play it :)
  205.         Dim threadid As Long
  206.         'open file for reading
  207.         Open cmd.FileName For Binary As #100
  208.         cthread = CreateThread(ByVal 0&, 0, AddressOf MemoryFileThread, FileLen(cmd.FileName), 0, threadid)   'threadid param required on win9x
  209.     End If
  210. End Sub
  211. Public Sub chkSYNC_Click()
  212.     If chkSYNC.value = vbChecked Then
  213.         SyncEnd = BASS_ChannelSetSync(chan, BASS_SYNC_END, 0, AddressOf SYNCtest.SyncEndTest, 0)
  214.     Else
  215.         Call BASS_ChannelRemoveSync(chan, SyncEnd)
  216.     End If
  217. End Sub
  218. Private Sub tmrBASS_Timer()
  219.     With bassTime
  220.         lblPos.Caption = "Playing Position: " & Format(.GetPlayingPos(chan), "0.0") & " seconds"
  221.         lblMins.Caption = "Time: " & .GetTime(.GetDuration(chan) - .GetPlayingPos(chan))
  222.     End With
  223. End Sub
  224. '--------------------------
  225. ' some useful functions :)
  226. '--------------------------
  227. 'check if any file exists
  228. Public Function FileExists(ByVal fp As String) As Boolean
  229.     FileExists = (Dir(fp) <> "")
  230. End Function
  231. 'RPP = Return Proper Path
  232. Public Function RPP(ByVal fp As String) As String
  233.     RPP = IIf(Mid(fp, Len(fp), 1) = "\", fp, fp & "\")
  234. End Function
  235. 'get file name from file path
  236. Public Function GetFileName(ByVal fp As String) As String
  237.     GetFileName = Mid(fp, InStrRev(fp, "\") + 1)
  238. End Function
  239.