home *** CD-ROM | disk | FTP | other *** search
/ Multimédia la Compil' 2 / Sybex_Multimedia_La_Compil_2.iso / cooltool / songplay / songplay.frm < prev    next >
Text File  |  1995-04-20  |  12KB  |  445 lines

  1. VERSION 2.00
  2. Begin Form SongPlayer 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "MCI MIDI Song Player"
  6.    ClientHeight    =   1635
  7.    ClientLeft      =   1425
  8.    ClientTop       =   2595
  9.    ClientWidth     =   4890
  10.    ForeColor       =   &H00C0C0C0&
  11.    Height          =   2325
  12.    Icon            =   SONGPLAY.FRX:0000
  13.    Left            =   1365
  14.    LinkMode        =   1  'Source
  15.    LinkTopic       =   "Form1"
  16.    MaxButton       =   0   'False
  17.    ScaleHeight     =   1635
  18.    ScaleWidth      =   4890
  19.    Top             =   1965
  20.    Width           =   5010
  21.    Begin CommandButton Cmd_Rewind 
  22.       Caption         =   "Rewind"
  23.       Enabled         =   0   'False
  24.       Height          =   675
  25.       Left            =   3720
  26.       TabIndex        =   8
  27.       Top             =   60
  28.       Width           =   1125
  29.    End
  30.    Begin CommandButton Cmd_Stop 
  31.       Caption         =   "Stop"
  32.       Enabled         =   0   'False
  33.       Height          =   675
  34.       Left            =   2580
  35.       TabIndex        =   7
  36.       Top             =   60
  37.       Width           =   1125
  38.    End
  39.    Begin CommandButton Cmd_Play 
  40.       Caption         =   "Play"
  41.       Enabled         =   0   'False
  42.       Height          =   675
  43.       Left            =   1440
  44.       TabIndex        =   6
  45.       Top             =   60
  46.       Width           =   1125
  47.    End
  48.    Begin Frame Frame2 
  49.       BackColor       =   &H00C0C0C0&
  50.       Caption         =   "Measure Controls"
  51.       Height          =   765
  52.       Left            =   1440
  53.       TabIndex        =   4
  54.       Top             =   810
  55.       Width           =   3405
  56.       Begin HSlider MeasureScroll 
  57.          BackColor       =   &H00C0C0C0&
  58.          BevelInner      =   0  'None
  59.          BevelOuter      =   1  'Raised
  60.          BevelWidth      =   1
  61.          BorderWidth     =   1
  62.          Gap             =   3
  63.          Height          =   285
  64.          LargeChange     =   10
  65.          Left            =   120
  66.          LinkControl     =   ""
  67.          LinkProperty    =   ""
  68.          Max             =   100
  69.          Min             =   1
  70.          ThumbHeight     =   270
  71.          ThumbStyle      =   2  'Pointed Down
  72.          ThumbWidth      =   240
  73.          TickColor       =   &H00000000&
  74.          TickCount       =   5
  75.          TickLength      =   4
  76.          TickMarks       =   3  'Both
  77.          TickWidth       =   1
  78.          Top             =   330
  79.          TrackBevel      =   1  'Raised
  80.          TrackWidth      =   0
  81.          Value           =   0
  82.          Width           =   3165
  83.       End
  84.    End
  85.    Begin Frame Frame1 
  86.       BackColor       =   &H00C0C0C0&
  87.       Caption         =   "Song &Tempo"
  88.       Height          =   765
  89.       Left            =   60
  90.       TabIndex        =   2
  91.       Top             =   810
  92.       Width           =   1275
  93.       Begin VSlider VSliderTempo 
  94.          BackColor       =   &H00C0C0C0&
  95.          BevelInner      =   0  'None
  96.          BevelOuter      =   0  'None
  97.          BevelWidth      =   2
  98.          BorderWidth     =   2
  99.          Gap             =   3
  100.          Height          =   465
  101.          LargeChange     =   10
  102.          Left            =   870
  103.          LinkControl     =   ""
  104.          LinkProperty    =   ""
  105.          Max             =   250
  106.          Min             =   0
  107.          ThumbHeight     =   140
  108.          ThumbStyle      =   1  'Pointed Left
  109.          ThumbWidth      =   200
  110.          TickColor       =   &H00000000&
  111.          TickCount       =   3
  112.          TickLength      =   4
  113.          TickMarks       =   1  'Left
  114.          TickWidth       =   1
  115.          Top             =   270
  116.          TrackBevel      =   1  'Raised
  117.          TrackWidth      =   0
  118.          Value           =   100
  119.          Width           =   255
  120.       End
  121.       Begin TextBox TempoLabel 
  122.          Alignment       =   2  'Center
  123.          BackColor       =   &H00C0C0C0&
  124.          Enabled         =   0   'False
  125.          FontBold        =   0   'False
  126.          FontItalic      =   0   'False
  127.          FontName        =   "MS Sans Serif"
  128.          FontSize        =   12
  129.          FontStrikethru  =   0   'False
  130.          FontUnderline   =   0   'False
  131.          ForeColor       =   &H00FF0000&
  132.          Height          =   420
  133.          Left            =   180
  134.          TabIndex        =   3
  135.          Text            =   "120"
  136.          Top             =   300
  137.          Width           =   645
  138.       End
  139.    End
  140.    Begin CommonDialog CMDialog1 
  141.       CancelError     =   -1  'True
  142.       Color           =   &H00C0C0C0&
  143.       DefaultExt      =   "mid"
  144.       DialogTitle     =   "Open Song File"
  145.       Left            =   780
  146.       PrinterDefault  =   0   'False
  147.       Top             =   1740
  148.    End
  149.    Begin Timer Timer1 
  150.       Interval        =   10
  151.       Left            =   9960
  152.       Top             =   165
  153.    End
  154.    Begin Label LabelSongLength 
  155.       Alignment       =   2  'Center
  156.       BackColor       =   &H00C0C0C0&
  157.       BorderStyle     =   1  'Fixed Single
  158.       Caption         =   "Total Length 0:00"
  159.       FontBold        =   0   'False
  160.       FontItalic      =   0   'False
  161.       FontName        =   "Small Fonts"
  162.       FontSize        =   6.75
  163.       FontStrikethru  =   0   'False
  164.       FontUnderline   =   0   'False
  165.       Height          =   225
  166.       Left            =   60
  167.       TabIndex        =   1
  168.       Top             =   450
  169.       Width           =   1305
  170.    End
  171.    Begin Label Label1 
  172.       Alignment       =   2  'Center
  173.       BackColor       =   &H00000000&
  174.       BorderStyle     =   1  'Fixed Single
  175.       Caption         =   "0:00"
  176.       FontBold        =   -1  'True
  177.       FontItalic      =   0   'False
  178.       FontName        =   "MS Sans Serif"
  179.       FontSize        =   9.75
  180.       FontStrikethru  =   0   'False
  181.       FontUnderline   =   0   'False
  182.       ForeColor       =   &H0000FF00&
  183.       Height          =   315
  184.       Left            =   60
  185.       TabIndex        =   5
  186.       Top             =   60
  187.       Width           =   1305
  188.    End
  189.    Begin Label readout 
  190.       Alignment       =   2  'Center
  191.       BackColor       =   &H00FF0000&
  192.       BorderStyle     =   1  'Fixed Single
  193.       Caption         =   "ErrorCode"
  194.       ForeColor       =   &H00FFFFFF&
  195.       Height          =   225
  196.       Left            =   6660
  197.       TabIndex        =   0
  198.       Top             =   4890
  199.       Width           =   1515
  200.    End
  201.    Begin Menu MnuFile 
  202.       Caption         =   "&File"
  203.       Begin Menu MnuOpenSong 
  204.          Caption         =   "&Open Song"
  205.          Shortcut        =   ^O
  206.       End
  207.       Begin Menu MnuLine 
  208.          Caption         =   "-"
  209.       End
  210.       Begin Menu MnuExit 
  211.          Caption         =   "E&xit"
  212.       End
  213.    End
  214.    Begin Menu mnuSettings 
  215.       Caption         =   "Settings"
  216.       Begin Menu mnuSettingsMIDI 
  217.          Caption         =   "&MIDI..."
  218.       End
  219.    End
  220. End
  221. Dim LastBar, CurrentBar As Integer
  222.  
  223. ' This MCI example only uses MIDI CoolTools to access different MIDI Output port.
  224. ' All the MIDI file playing is being performed by the Windows MCI. The MCI does not
  225. ' give you low level access to any of the actual MIDI data, but can be very useful
  226. ' for playing MIDI files that contain less than 32 tracks.
  227.  
  228. ' For more information on the MCI for playing MIDI, WAVE and CD-ROM audio, please
  229. ' Refer to the Microsoft Windows Multimedia Progrmmer's Reference.
  230. ' Available from Microsoft Press at 800-MSPRESS
  231.  
  232.  
  233.  
  234.  
  235.  
  236. Sub Cmd_Play_Click ()
  237.     Dim i As Integer
  238.     Dim X As Integer
  239.     Dim Action As String
  240.  
  241.     Screen.MousePointer = 11
  242.     
  243.     Action = "Set " + "MCIMidi " + "Port " + Str$(MIDISetupForm.ComboMidiOut.ListIndex - 1)
  244.     i = mciExecute(Action)
  245.  
  246.     If SongLength = CurrentBar Then
  247.         Action = "SEEK " + "MCIMidi " + "TO START"
  248.         i = mciExecute(Action)
  249.         Action = "Play " + "MCIMidi "
  250.         MidiBarNumber = 0
  251.         Label1.Caption = " 0:00"
  252.     Else
  253.         If MeasureScroll.Value = CurrentBar Then
  254.             Action = "Play " + "MCIMidi "
  255.         Else
  256.             Action = "Play " + "MCIMidi " + "from " + Str$(MeasureScroll.Value * 4)
  257.         End If
  258.     End If
  259.     i = mciExecute(Action)
  260.     SetTempo
  261.  
  262.     MeasureScroll.Enabled = False
  263.  
  264.     Cmd_Play.Enabled = False
  265.     Cmd_stop.Enabled = True
  266.     
  267.     Screen.MousePointer = 0
  268.     Timer1.Enabled = True
  269.  
  270. End Sub
  271.  
  272. Sub Cmd_Rewind_Click ()
  273.     Dim i As Integer
  274.     Dim X As Integer
  275.  
  276.     Screen.MousePointer = 11
  277.  
  278.     Label1.Caption = " 0:00"
  279.     MeasureScroll.Value = 1
  280.  
  281.     Action$ = "SEEK " + "MCIMidi " + "TO START"
  282.     i = mciExecute(Action$)
  283.     
  284.     MidiBarNumber = 0
  285.     MeasureScroll.Enabled = True
  286.  
  287.     Cmd_Play.Enabled = True
  288.     Cmd_stop.Enabled = False
  289.     
  290.     Screen.MousePointer = 0
  291. End Sub
  292.  
  293. Sub Cmd_Stop_Click ()
  294.     Dim i As Integer
  295.     
  296.     Screen.MousePointer = 11
  297.  
  298.     Timer1.Enabled = False
  299.     
  300.     Action$ = "Pause " + "MCIMidi"
  301.     i = mciExecute(Action$)
  302.     
  303.     MidiBarNumber = 0
  304.     MeasureScroll.Enabled = True
  305.  
  306.     Cmd_Play.Enabled = True
  307.     Cmd_stop.Enabled = False
  308.     
  309.     Screen.MousePointer = 0
  310. End Sub
  311.  
  312. Sub Form_Load ()
  313.    On Error GoTo ErrorHandler:
  314.  
  315.     SongFileOpened = False
  316.     SongLength = 1
  317.     CurrentBar = 0
  318.  
  319. ErrorHandler:
  320.     If Err > 0 Then
  321.         Msg$ = "Unanticipated error number" + Str$(Err) + " occurred: " + Error$
  322.         MsgBox Msg$, 16
  323.         End
  324.     End If
  325. End Sub
  326.  
  327. Sub Form_Unload (Cancel As Integer)
  328.     Dim Action As String
  329.     Dim X As Integer
  330.     
  331.     Action$ = "close all"
  332.     X = mciExecute(Action$)
  333.             
  334.     End
  335. End Sub
  336.  
  337. Sub MeasureScroll_Change ()
  338.     If SongTempo > 0 Then Label1.Caption = Str$(Int((60 / SongTempo) * Int(Val(MeasureScroll.Value)) / 60)) + ":" + Format$(Int((60 / SongTempo) * Int(Val(MeasureScroll.Value))) Mod 60, "00")
  339. End Sub
  340.  
  341. Sub MnuExit_Click ()
  342.     Dim Action As String
  343.     Dim X As Integer
  344.  
  345.     Action$ = "close all"
  346.     X = mciExecute(Action$)
  347.             
  348.     End
  349. End Sub
  350.  
  351. Sub MnuOpenSong_Click ()
  352.     OpenSongFile
  353. End Sub
  354.  
  355. Sub mnuSettingsMidi_Click ()
  356.     MIDISetupForm.Show
  357.     Action$ = "Set " + "MCIMidi " + "Port " + Str$(MIDISetupForm.ComboMidiOut.ListIndex - 1)
  358.     i = mciExecute(Action$)
  359. End Sub
  360.  
  361. Sub SSCommand1_Click ()
  362.     
  363. End Sub
  364.  
  365. Sub TempoLabel_KeyPress (KeyAscii As Integer)
  366.     If KeyAscii = 13 Then
  367.         Cmd_Rewind.SetFocus
  368.     End If
  369.     If Len(LTrim$(TempoLabel.Text)) > 3 Then
  370.         Beep
  371.         KeyAscii = 0
  372.     End If
  373.     c$ = Chr$(KeyAscii)
  374.     If c$ < "0" Or c$ > "9" Then
  375.         KeyAscii = 0
  376.     End If
  377. End Sub
  378.  
  379. Sub TempoLabel_LostFocus ()
  380.     If Val(TempoLabel.Text) > 0 And Val(TempoLabel.Text) < 1000 Then
  381.         SongTempo = Val(TempoLabel.Text)
  382.         SetTempo
  383.     End If
  384.     If Val(TempoLabel.Text) > 999 Then
  385.         TempoLabel.Text = "999"
  386.         SongTempo = Val(TempoLabel.Text)
  387.         SetTempo
  388.     End If
  389.     If Val(TempoLabel.Text) = 0 Then
  390.         TempoLabel.Text = "1"
  391.         SongTempo = Val(TempoLabel.Text)
  392.         SetTempo
  393.     End If
  394. End Sub
  395.  
  396. Sub TempoSpin1_SpinDown ()
  397.     If SongTempo < 2 Then
  398.         SongTempo = 999
  399.     Else
  400.        SongTempo = SongTempo - 1
  401.     End If
  402.  
  403.     TempoLabel.Text = Str$(SongTempo)
  404.     TempoLabel.Refresh
  405.     SetTempo
  406. End Sub
  407.  
  408. Sub TempoSpin1_SpinUp ()
  409.     If SongTempo > 998 Then
  410.         SongTempo = 1
  411.     Else
  412.        SongTempo = SongTempo + 1
  413.     End If
  414.  
  415.     TempoLabel.Text = Str$(SongTempo)
  416.     TempoLabel.Refresh
  417.     SetTempo
  418. End Sub
  419.  
  420. Sub Timer1_Timer ()
  421.     If SongFileOpened = True Then
  422.         Dim j, k, L As Integer
  423.         Dim RtnString As String, i As String
  424.         j = 100
  425.         k = 0
  426.         RtnString = "                                "
  427.         Action$ = "Status " + "MCIMidi " + "Position"
  428.         i$ = mciSendString(Action$, RtnString, j, k)
  429.  
  430.         CurrentBar = Int(Val(RtnString) / 4)
  431.         If LastBar <> CurrentBar Then
  432.             LastBar = CurrentBar
  433.             MeasureScroll.Value = CurrentBar
  434.         End If
  435.         RtnString = "                                "
  436.     End If
  437. End Sub
  438.  
  439. Sub VSliderTempo_Change ()
  440.     SongTempo = VSliderTempo.Value
  441.     TempoLabel.Text = Str$(SongTempo)
  442.     SetTempo
  443. End Sub
  444.  
  445.