home *** CD-ROM | disk | FTP | other *** search
/ Multimédia la Compil' 2 / Sybex_Multimedia_La_Compil_2.iso / cooltool / songplay / songplay.bas < prev    next >
BASIC Source File  |  1995-04-20  |  3KB  |  111 lines

  1. ' MIDI and MCI API
  2. Declare Function mciExecute Lib "mmsystem.dll" (ByVal a$) As Integer
  3. Declare Function mciSendString Lib "mmsystem.dll" (ByVal lpstrCommand$, ByVal lpstrRtnString$, ByVal wRtnLength As Integer, ByVal hCallback As Integer) As String
  4.  
  5. Global FullFilePath As String
  6. Global SongFileOpened As Integer
  7. Global SongTempo As Integer
  8. Global SongLength As Integer
  9.  
  10. 'Current MIDI Out Port that is selected
  11. Global MidiOutPort As Integer
  12.  
  13. ' Booleans
  14. Global Const MODAL = 1
  15.  
  16. Sub GetSongLength ()
  17.     Dim RtnString As String
  18.     Dim Action As String
  19.  
  20.     RtnString = Space(32)
  21.     Action = "Status " + "MCIMidi " + "length"
  22.     Action = mciSendString(Action, RtnString, 100, 0)
  23.     SongLength = Int(Val(RtnString) / 4)
  24.     SongPlayer.LabelSongLength.Caption = "Total Length " + Str$(Int((60 / SongTempo) * SongLength / 60)) + ":" + Format$(Int((60 / SongTempo) * SongLength) Mod 60, "00")
  25. End Sub
  26.  
  27. Sub GetSongTempo ()
  28.     Dim RtnString As String
  29.     Dim Action As String
  30.  
  31.     RtnString = Space(32)
  32.     Action = "Status " + "MCIMidi " + "tempo"
  33.     Action = mciSendString(Action$, RtnString, 100, 0)
  34.     SongTempo = Val(RtnString)
  35. End Sub
  36.  
  37. Sub OpenSongFile ()
  38.     Dim I As Integer
  39.     Screen.MousePointer = 11
  40.         
  41.     SongPlayer.CMDialog1.DialogTitle = "Open Song File"
  42.     ' Set the "Open File..." dialog to display *.mid files.
  43.     SongPlayer.CMDialog1.Filter = "MIDI File (*.mid)|*.mid"
  44.         
  45.  
  46.     ' Display the File Open... dialog.
  47.     SongPlayer.CMDialog1.FilterIndex = 1
  48.     SongPlayer.CMDialog1.Flags = OFN_READONLY Or OFN_FILEMUSTEXIST
  49.     SongPlayer.CMDialog1.CancelError = True
  50.     SongPlayer.CMDialog1.Filename = ""
  51.     On Error Resume Next
  52.     SongPlayer.CMDialog1.Action = 1
  53.  
  54.     If Err <> 0 Then
  55.     ' No file selected from the "Open File..." dialog.
  56.     Screen.MousePointer = 0
  57.     Exit Sub
  58.     End If
  59.  
  60.     SongPlayer.Caption = "MCI Song Player - " + SongPlayer.CMDialog1.Filetitle
  61.     If SongFileOpened = True Then
  62.     ' Close previous song file
  63.     Action$ = "Close " + "MCIMidi"
  64.     I = mciExecute(Action$)
  65.     End If
  66.     
  67.     ' Open selected song file
  68.     Action$ = "Open " + SongPlayer.CMDialog1.Filename + " alias " + "MCIMidi"
  69.     I = mciExecute(Action$)
  70.  
  71.     On Error GoTo 0
  72.     
  73.     SongFileOpened = True
  74.     
  75.     RewindFlag = True
  76.     SongPlayer.Label1.Caption = " 0:00"
  77.     SongPlayer.MeasureScroll.Value = 0
  78.  
  79.     ' Get song tempo
  80.     GetSongTempo
  81.     SongPlayer.TempoLabel.Text = Str$(SongTempo)
  82.     
  83.     ' Get song length
  84.     GetSongLength
  85.     
  86.     ' Setup Measure Scroll Bar
  87.     SongPlayer.MeasureScroll.Max = SongLength
  88.     
  89.     'Enable the play control once SMF is loaded
  90.     SongPlayer.Cmd_Play.Enabled = True
  91.     SongPlayer.Cmd_Stop.Enabled = False
  92.     SongPlayer.Cmd_Rewind.Enabled = True
  93.     SongPlayer.MeasureScroll.Enabled = True
  94.     SongPlayer.VSliderTempo.Enabled = True
  95.     SongPlayer.TempoLabel.Enabled = True
  96.  
  97.     Screen.MousePointer = 0
  98. End Sub
  99.  
  100. Sub SetTempo ()
  101.     Dim I As Integer
  102.  
  103.     If SongFileOpened = True Then
  104.     'Set song tempo
  105.     Action$ = "SET " + "MCIMidi " + "TEMPO " + Str$(SongTempo)
  106.     I = mciExecute(Action$)
  107.     SongPlayer.LabelSongLength.Caption = "Total Length " + Str$(Int((60 / SongTempo) * SongLength / 60)) + ":" + Format$(Int((60 / SongTempo) * SongLength) Mod 60, "00")
  108.     End If
  109. End Sub
  110.  
  111.