home *** CD-ROM | disk | FTP | other *** search
/ Multimédia la Compil' 2 / Sybex_Multimedia_La_Compil_2.iso / cooltool / mfedit / mfedit.frm next >
Text File  |  1995-04-20  |  36KB  |  1,178 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    AutoRedraw      =   -1  'True
  4.    BackColor       =   &H00C0C0C0&
  5.    BorderStyle     =   3  'Fixed Double
  6.    Caption         =   "MFEDIT"
  7.    ClientHeight    =   5355
  8.    ClientLeft      =   720
  9.    ClientTop       =   2070
  10.    ClientWidth     =   9240
  11.    Height          =   6045
  12.    Icon            =   MFEDIT.FRX:0000
  13.    Left            =   660
  14.    LinkTopic       =   "Form1"
  15.    MaxButton       =   0   'False
  16.    ScaleHeight     =   5355
  17.    ScaleWidth      =   9240
  18.    Top             =   1440
  19.    Width           =   9360
  20.    Begin Frame Frame3 
  21.       BackColor       =   &H00C0C0C0&
  22.       Caption         =   "Playback Rate"
  23.       Height          =   855
  24.       Left            =   7080
  25.       TabIndex        =   12
  26.       Top             =   2220
  27.       Width           =   2055
  28.       Begin HSlider PlaybackRateSlider 
  29.          BackColor       =   &H00C0C0C0&
  30.          BevelInner      =   1  'Raised
  31.          BevelOuter      =   0  'None
  32.          BevelWidth      =   2
  33.          BorderWidth     =   2
  34.          Gap             =   3
  35.          Height          =   435
  36.          LargeChange     =   10
  37.          Left            =   120
  38.          LinkControl     =   "MIDIOutput1"
  39.          LinkProperty    =   "PlaybackRate"
  40.          Max             =   100
  41.          Min             =   -100
  42.          ThumbHeight     =   340
  43.          ThumbStyle      =   2  'Pointed Down
  44.          ThumbWidth      =   120
  45.          TickColor       =   &H00000000&
  46.          TickCount       =   20
  47.          TickLength      =   4
  48.          TickMarks       =   2  'Bottom
  49.          TickWidth       =   1
  50.          Top             =   300
  51.          TrackBevel      =   2  'Inset
  52.          TrackWidth      =   2
  53.          Value           =   0
  54.          Width           =   1815
  55.       End
  56.    End
  57.    Begin Frame Frame5 
  58.       BackColor       =   &H00C0C0C0&
  59.       Caption         =   "Playback Controls"
  60.       Height          =   2115
  61.       Left            =   7080
  62.       TabIndex        =   30
  63.       Top             =   3180
  64.       Width           =   2055
  65.       Begin CommandButton CmdStop 
  66.          Caption         =   "Stop"
  67.          Height          =   435
  68.          Left            =   120
  69.          TabIndex        =   31
  70.          Top             =   1500
  71.          Width           =   1815
  72.       End
  73.       Begin CommandButton CmdRecord 
  74.          Caption         =   "Record"
  75.          Height          =   435
  76.          Left            =   120
  77.          TabIndex        =   32
  78.          Top             =   900
  79.          Width           =   1815
  80.       End
  81.       Begin CommandButton CmdPlay 
  82.          Caption         =   "Play"
  83.          Height          =   435
  84.          Left            =   120
  85.          TabIndex        =   33
  86.          Top             =   300
  87.          Width           =   1815
  88.       End
  89.    End
  90.    Begin Frame Frame4 
  91.       BackColor       =   &H00C0C0C0&
  92.       Caption         =   "MIDI File Settings"
  93.       Height          =   2175
  94.       Left            =   7080
  95.       TabIndex        =   36
  96.       Top             =   -30
  97.       Width           =   2055
  98.       Begin Label LabelTicks 
  99.          Alignment       =   2  'Center
  100.          BackColor       =   &H00000000&
  101.          Caption         =   "Tick"
  102.          FontBold        =   0   'False
  103.          FontItalic      =   0   'False
  104.          FontName        =   "MS Sans Serif"
  105.          FontSize        =   9.75
  106.          FontStrikethru  =   0   'False
  107.          FontUnderline   =   0   'False
  108.          ForeColor       =   &H0000FF00&
  109.          Height          =   255
  110.          Left            =   240
  111.          TabIndex        =   37
  112.          Top             =   1800
  113.          Width           =   1635
  114.       End
  115.       Begin Label LabelTimeSignature 
  116.          Alignment       =   2  'Center
  117.          BackColor       =   &H00000000&
  118.          BorderStyle     =   1  'Fixed Single
  119.          Caption         =   "Time Signature"
  120.          FontBold        =   0   'False
  121.          FontItalic      =   0   'False
  122.          FontName        =   "MS Sans Serif"
  123.          FontSize        =   9.75
  124.          FontStrikethru  =   0   'False
  125.          FontUnderline   =   0   'False
  126.          ForeColor       =   &H0000FF00&
  127.          Height          =   315
  128.          Left            =   240
  129.          TabIndex        =   34
  130.          Top             =   540
  131.          Width           =   1635
  132.       End
  133.       Begin Label LabelTempo 
  134.          Alignment       =   2  'Center
  135.          BackColor       =   &H00000000&
  136.          BorderStyle     =   1  'Fixed Single
  137.          Caption         =   "Tempo"
  138.          FontBold        =   0   'False
  139.          FontItalic      =   0   'False
  140.          FontName        =   "MS Sans Serif"
  141.          FontSize        =   9.75
  142.          FontStrikethru  =   0   'False
  143.          FontUnderline   =   0   'False
  144.          ForeColor       =   &H0000FF00&
  145.          Height          =   315
  146.          Left            =   240
  147.          TabIndex        =   35
  148.          Top             =   1140
  149.          Width           =   1635
  150.       End
  151.       Begin Label Label7 
  152.          Alignment       =   2  'Center
  153.          BackColor       =   &H00C0C0C0&
  154.          Caption         =   "Time Signature"
  155.          FontBold        =   0   'False
  156.          FontItalic      =   0   'False
  157.          FontName        =   "MS Sans Serif"
  158.          FontSize        =   9.75
  159.          FontStrikethru  =   0   'False
  160.          FontUnderline   =   0   'False
  161.          Height          =   255
  162.          Left            =   120
  163.          TabIndex        =   40
  164.          Top             =   300
  165.          Width           =   1815
  166.       End
  167.       Begin Label Label8 
  168.          Alignment       =   2  'Center
  169.          BackColor       =   &H00C0C0C0&
  170.          Caption         =   "Tempo"
  171.          FontBold        =   0   'False
  172.          FontItalic      =   0   'False
  173.          FontName        =   "MS Sans Serif"
  174.          FontSize        =   9.75
  175.          FontStrikethru  =   0   'False
  176.          FontUnderline   =   0   'False
  177.          Height          =   255
  178.          Left            =   120
  179.          TabIndex        =   39
  180.          Top             =   900
  181.          Width           =   1815
  182.       End
  183.       Begin Label Label9 
  184.          Alignment       =   2  'Center
  185.          BackColor       =   &H00C0C0C0&
  186.          Caption         =   "Ticks Per Quarter Note"
  187.          FontBold        =   0   'False
  188.          FontItalic      =   0   'False
  189.          FontName        =   "MS Sans Serif"
  190.          FontSize        =   8.25
  191.          FontStrikethru  =   0   'False
  192.          FontUnderline   =   0   'False
  193.          Height          =   255
  194.          Left            =   120
  195.          TabIndex        =   38
  196.          Top             =   1560
  197.          Width           =   1815
  198.       End
  199.    End
  200.    Begin MIDIFile MIDIFile1 
  201.       Filename        =   ""
  202.       Left            =   1440
  203.       ReadOnly        =   0   'False
  204.       Top             =   5340
  205.    End
  206.    Begin MIDIInput MIDIInput1 
  207.       DeviceID        =   0
  208.       Left            =   1860
  209.       MaxSysexSize    =   32000
  210.       MessageEventEnable=   0   'False
  211.       Top             =   5340
  212.    End
  213.    Begin PictureBox Picture1 
  214.       BackColor       =   &H00C0C0C0&
  215.       BorderStyle     =   0  'None
  216.       Height          =   435
  217.       Left            =   60
  218.       ScaleHeight     =   435
  219.       ScaleWidth      =   6915
  220.       TabIndex        =   19
  221.       Top             =   30
  222.       Width           =   6915
  223.       Begin CheckBox MidiThruCheck 
  224.          BackColor       =   &H00C0C0C0&
  225.          Caption         =   "Midi Thru"
  226.          Height          =   255
  227.          Left            =   2820
  228.          TabIndex        =   22
  229.          Top             =   60
  230.          Value           =   1  'Checked
  231.          Width           =   1155
  232.       End
  233.       Begin ComboBox InputDevCombo 
  234.          Height          =   300
  235.          Left            =   60
  236.          Style           =   2  'Dropdown List
  237.          TabIndex        =   18
  238.          Top             =   60
  239.          Width           =   2535
  240.       End
  241.       Begin ComboBox OutputDevCombo 
  242.          Height          =   300
  243.          Left            =   4140
  244.          Style           =   2  'Dropdown List
  245.          TabIndex        =   20
  246.          Top             =   60
  247.          Width           =   2535
  248.       End
  249.    End
  250.    Begin Frame Frame2 
  251.       BackColor       =   &H00C0C0C0&
  252.       Caption         =   "Tracks"
  253.       ForeColor       =   &H00000000&
  254.       Height          =   4755
  255.       Left            =   60
  256.       TabIndex        =   13
  257.       Top             =   540
  258.       Width           =   3195
  259.       Begin ListBox TrackList 
  260.          Height          =   2955
  261.          Left            =   120
  262.          TabIndex        =   17
  263.          Top             =   300
  264.          Width           =   2955
  265.       End
  266.       Begin CommandButton CmdInsertTrack 
  267.          Caption         =   "Insert New Track"
  268.          Height          =   435
  269.          Left            =   120
  270.          TabIndex        =   16
  271.          Top             =   4260
  272.          Width           =   2955
  273.       End
  274.       Begin CommandButton CmdDeleteTrack 
  275.          Caption         =   "Delete Current Track"
  276.          Height          =   435
  277.          Left            =   120
  278.          TabIndex        =   15
  279.          Top             =   3780
  280.          Width           =   2955
  281.       End
  282.       Begin CommandButton CmdQueueTrack 
  283.          Caption         =   "Queue Current Track"
  284.          Height          =   435
  285.          Left            =   120
  286.          TabIndex        =   14
  287.          Top             =   3300
  288.          Width           =   2955
  289.       End
  290.    End
  291.    Begin MIDIOutput MIDIOutput1 
  292.       DeviceID        =   0
  293.       Left            =   2280
  294.       Top             =   5340
  295.       VolumeLeft      =   0
  296.       VolumeRight     =   0
  297.    End
  298.    Begin CommonDialog CMDialog1 
  299.       CancelError     =   -1  'True
  300.       DefaultExt      =   "mid"
  301.       DialogTitle     =   "Open MIDI File"
  302.       Filter          =   "(*.mid) MIDI files|*.mid|"
  303.       Left            =   2700
  304.       Top             =   5340
  305.    End
  306.    Begin Frame Frame1 
  307.       BackColor       =   &H00C0C0C0&
  308.       Caption         =   "Messages"
  309.       Height          =   4755
  310.       Left            =   3300
  311.       TabIndex        =   4
  312.       Top             =   540
  313.       Width           =   3675
  314.       Begin PictureBox Picture2 
  315.          BackColor       =   &H00C0C0C0&
  316.          BorderStyle     =   0  'None
  317.          Height          =   1875
  318.          Left            =   120
  319.          ScaleHeight     =   1875
  320.          ScaleWidth      =   3495
  321.          TabIndex        =   23
  322.          Top             =   2820
  323.          Width           =   3495
  324.          Begin TextBox MessageEdit 
  325.             Height          =   285
  326.             Left            =   1020
  327.             TabIndex        =   29
  328.             Top             =   60
  329.             Width           =   555
  330.          End
  331.          Begin TextBox Data1Edit 
  332.             Height          =   285
  333.             Left            =   1020
  334.             TabIndex        =   28
  335.             Top             =   420
  336.             Width           =   555
  337.          End
  338.          Begin TextBox Data2Edit 
  339.             Height          =   285
  340.             Left            =   2700
  341.             TabIndex        =   27
  342.             Top             =   420
  343.             Width           =   555
  344.          End
  345.          Begin TextBox TimeEdit 
  346.             Height          =   285
  347.             Left            =   1020
  348.             TabIndex        =   26
  349.             Top             =   780
  350.             Width           =   1035
  351.          End
  352.          Begin TextBox BufferEdit 
  353.             Height          =   285
  354.             Left            =   1020
  355.             TabIndex        =   25
  356.             Top             =   1140
  357.             Width           =   2415
  358.          End
  359.          Begin TextBox MsgTextEdit 
  360.             Height          =   285
  361.             Left            =   1020
  362.             TabIndex        =   24
  363.             Top             =   1500
  364.             Width           =   2415
  365.          End
  366.          Begin Label Label1 
  367.             Alignment       =   1  'Right Justify
  368.             BackColor       =   &H00C0C0C0&
  369.             Caption         =   "Message:"
  370.             Height          =   255
  371.             Left            =   60
  372.             TabIndex        =   6
  373.             Top             =   60
  374.             Width           =   855
  375.          End
  376.          Begin Label Label2 
  377.             Alignment       =   1  'Right Justify
  378.             BackColor       =   &H00C0C0C0&
  379.             Caption         =   "Data1:"
  380.             Height          =   255
  381.             Left            =   60
  382.             TabIndex        =   7
  383.             Top             =   420
  384.             Width           =   855
  385.          End
  386.          Begin Label Label3 
  387.             Alignment       =   1  'Right Justify
  388.             BackColor       =   &H00C0C0C0&
  389.             Caption         =   "Data2:"
  390.             Height          =   255
  391.             Left            =   1740
  392.             TabIndex        =   8
  393.             Top             =   420
  394.             Width           =   855
  395.          End
  396.          Begin Label Label4 
  397.             Alignment       =   1  'Right Justify
  398.             BackColor       =   &H00C0C0C0&
  399.             Caption         =   "Buffer:"
  400.             Height          =   255
  401.             Left            =   60
  402.             TabIndex        =   9
  403.             Top             =   1140
  404.             Width           =   855
  405.          End
  406.          Begin Label Label5 
  407.             Alignment       =   1  'Right Justify
  408.             BackColor       =   &H00C0C0C0&
  409.             Caption         =   "Time:"
  410.             Height          =   255
  411.             Left            =   60
  412.             TabIndex        =   10
  413.             Top             =   780
  414.             Width           =   855
  415.          End
  416.          Begin Label Label6 
  417.             BackColor       =   &H00C0C0C0&
  418.             Caption         =   "MsgText:"
  419.             Height          =   255
  420.             Left            =   120
  421.             TabIndex        =   11
  422.             Top             =   1500
  423.             Width           =   795
  424.          End
  425.       End
  426.       Begin CheckBox InsertRecordingCheck 
  427.          BackColor       =   &H00C0C0C0&
  428.          Caption         =   "Insert Recording"
  429.          Height          =   255
  430.          Left            =   1620
  431.          TabIndex        =   21
  432.          Top             =   2520
  433.          Width           =   1755
  434.       End
  435.       Begin CommandButton CmdDeleteMessage 
  436.          Caption         =   "Delete"
  437.          Height          =   315
  438.          Left            =   2700
  439.          TabIndex        =   0
  440.          Top             =   2160
  441.          Width           =   855
  442.       End
  443.       Begin CommandButton CmdInsertMessage 
  444.          Caption         =   "Insert"
  445.          Height          =   315
  446.          Left            =   1440
  447.          TabIndex        =   1
  448.          Top             =   2160
  449.          Width           =   855
  450.       End
  451.       Begin CommandButton CmdModifyMessage 
  452.          Caption         =   "Modify"
  453.          Height          =   315
  454.          Left            =   120
  455.          TabIndex        =   2
  456.          Top             =   2160
  457.          Width           =   855
  458.       End
  459.       Begin CheckBox HexCheck 
  460.          BackColor       =   &H00C0C0C0&
  461.          Caption         =   "Hexadecimal"
  462.          Height          =   255
  463.          Left            =   180
  464.          TabIndex        =   3
  465.          Top             =   2520
  466.          Value           =   1  'Checked
  467.          Width           =   1455
  468.       End
  469.       Begin ListBox MessageList 
  470.          Height          =   1785
  471.          Left            =   120
  472.          TabIndex        =   5
  473.          Top             =   300
  474.          Width           =   3435
  475.       End
  476.    End
  477.    Begin Menu FileMenu 
  478.       Caption         =   "&File"
  479.       Begin Menu FileNew 
  480.          Caption         =   "&New"
  481.          Shortcut        =   ^N
  482.       End
  483.       Begin Menu FileOpen 
  484.          Caption         =   "&Open..."
  485.          Shortcut        =   ^O
  486.       End
  487.       Begin Menu FileSep1 
  488.          Caption         =   "-"
  489.       End
  490.       Begin Menu FileSave 
  491.          Caption         =   "&Save"
  492.          Shortcut        =   ^S
  493.       End
  494.       Begin Menu FileSaveAs 
  495.          Caption         =   "Save &As..."
  496.       End
  497.       Begin Menu FileSep2 
  498.          Caption         =   "-"
  499.       End
  500.       Begin Menu FileExit 
  501.          Caption         =   "E&xit"
  502.       End
  503.    End
  504. End
  505. Option Explicit
  506.  
  507. Dim lVolume As Integer
  508. Dim rVolume As Integer
  509.  
  510.  
  511. Dim msPerTick(50) As Long
  512. Dim ticksPerMs(50) As Long
  513.  
  514. Dim fModified As Integer
  515. Dim fGotFirst As Integer
  516. Dim fRecording As Integer
  517.  
  518. Dim CurrentTime As Double
  519. Dim PreviousTime As Double
  520. Dim InCurrentTime As Double
  521. Dim InPreviousTime As Double
  522.  
  523. Dim TempoTime(50) As Long
  524.  
  525. Dim TempoSetting(50) As Long
  526. Dim TotalTempoChanges As Integer
  527.  
  528. Dim Lyric(1000) As String
  529.  
  530. Sub CloseInputDevice ()
  531.     '
  532.     ' Close if open
  533.     '
  534.     If MIDIInput1.State >= MIDISTATE_OPEN Then
  535.         MIDIInput1.Action = MIDIIN_CLOSE
  536.     End If
  537. End Sub
  538.  
  539. Sub CloseOutputDevice ()
  540.     '
  541.     ' Restore volume before closing
  542.     '
  543.     If MIDIOutput1.State >= MIDISTATE_OPEN Then
  544.         If (MIDIOutput1.HasLRVolume) Then
  545.             MIDIOutput1.VolumeLeft = lVolume
  546.             MIDIOutput1.VolumeRight = rVolume
  547.         ElseIf (MIDIOutput1.HasVolume) Then
  548.             MIDIOutput1.VolumeLeft = lVolume
  549.         End If
  550.         '
  551.         ' Close
  552.         '
  553.         MIDIOutput1.Action = MIDIOUT_CLOSE
  554.     End If
  555. End Sub
  556.  
  557. Sub CmdDeleteMessage_Click ()
  558.     MIDIFile1.Action = MIDIFILE_DELETE_MESSAGE
  559.     fModified = True
  560.     DisplayTrack (TrackList.ListIndex + 1)
  561. End Sub
  562.  
  563. Sub CmdDeleteTrack_Click ()
  564.     Dim t As Integer
  565.  
  566.     MIDIFile1.TrackNumber = TrackList.ListIndex + 1
  567.     MIDIFile1.Action = MIDIFILE_DELETE_TRACK
  568.     fModified = True
  569.     t = TrackList.ListIndex
  570.     DisplayTrackList
  571.     If (t > TrackList.ListCount - 1) Then
  572.         t = t - 1
  573.     End If
  574.     TrackList.ListIndex = t
  575. End Sub
  576.  
  577. Sub CmdInsertMessage_Click ()
  578.     MIDIFile1.Message = FetchNumber(CStr(MessageEdit.Text))
  579.     MIDIFile1.Data1 = FetchNumber(CStr(Data1Edit.Text))
  580.     MIDIFile1.Data2 = FetchNumber(CStr(Data2Edit.Text))
  581.     MIDIFile1.Time = FetchNumber(CStr(TimeEdit.Text))
  582.     MIDIFile1.Action = MIDIFILE_INSERT_MESSAGE
  583.     fModified = True
  584.     DisplayTrack (TrackList.ListIndex + 1)
  585. End Sub
  586.  
  587. Sub CmdInsertTrack_Click ()
  588.     Dim t As Integer
  589.  
  590.     MIDIFile1.TrackNumber = TrackList.ListIndex + 1
  591.     MIDIFile1.Action = MIDIFILE_INSERT_TRACK
  592.     fModified = True
  593.     t = TrackList.ListIndex
  594.     DisplayTrackList
  595.     TrackList.ListIndex = t + 1
  596. End Sub
  597.  
  598. Sub CmdModifyMessage_Click ()
  599.     Dim m As Integer
  600.  
  601.     MIDIFile1.Message = FetchNumber(CStr(MessageEdit.Text))
  602.     MIDIFile1.Data1 = FetchNumber(CStr(Data1Edit.Text))
  603.     MIDIFile1.Data2 = FetchNumber(CStr(Data2Edit.Text))
  604.     MIDIFile1.Time = FetchNumber(CStr(TimeEdit.Text))
  605.     MIDIFile1.Buffer = BufferEdit.Text
  606.     MIDIFile1.MsgText = MsgTextEdit.Text
  607.     MIDIFile1.Action = MIDIFILE_MODIFY_MESSAGE
  608.     m = MIDIFile1.MessageNumber
  609.     fModified = True
  610.     DisplayTrack (TrackList.ListIndex + 1)
  611.     If (m > MIDIFile1.MessageCount) Then
  612.         m = m - 1
  613.     End If
  614.     MessageList.ListIndex = m
  615. End Sub
  616.  
  617. Sub CmdPlay_Click ()
  618.     StartPlay
  619. End Sub
  620.  
  621. Sub CmdQueueTrack_Click ()
  622.     QueueTrack (TrackList.ListIndex + 1)
  623.     On Error Resume Next
  624.     TrackList.ListIndex = TrackList.ListIndex + 1
  625.     On Error GoTo 0
  626. End Sub
  627.  
  628. Sub CmdRecord_Click ()
  629.     InsertRecordingCheck.Value = 1
  630.     StartPlay
  631.     StartRecording
  632. End Sub
  633.  
  634. Sub CmdStop_Click ()
  635.     StopPlay
  636.     StopRecording
  637. End Sub
  638.  
  639. Sub DisplayTrack (t As Integer)
  640.     Dim i As Integer
  641.  
  642.     Screen.MousePointer = 11
  643.     MessageList.Clear
  644.     MIDIFile1.TrackNumber = t
  645.     For i = 1 To MIDIFile1.MessageCount
  646.         If (i > 500) Then
  647.             Exit For
  648.         End If
  649.         MIDIFile1.MessageNumber = i
  650.  
  651.         '
  652.         'Meta Event
  653.         '
  654.         If (MIDIFile1.Message = 255) Then
  655.             Select Case MIDIFile1.Data1
  656.                 Case 0 'Sequence number
  657.                     MessageList.AddItem "Sequence number " & Hex$(MIDIFile1.Data2) & " : " & MIDIFile1.MsgText
  658.                 Case 1 'Text
  659.                     MessageList.AddItem "Text " & Hex$(MIDIFile1.Data1) & " : " & MIDIFile1.MsgText
  660.                 Case 2 'Copyright
  661.                     MessageList.AddItem "Copyright " & Hex$(MIDIFile1.Data1) & " : " & MIDIFile1.MsgText
  662.                 Case 3 'track name
  663.                     MessageList.AddItem "Track Name " & Hex$(MIDIFile1.Data1) & " : " & MIDIFile1.MsgText
  664.                 Case 4 'instrument name
  665.                     MessageList.AddItem "Instrument Name " & Hex$(MIDIFile1.Data1) & " : " & MIDIFile1.MsgText
  666.                 Case 5 'Lyric
  667.                     MessageList.AddItem "Lyric " & Hex$(MIDIFile1.Data1) & " : " & MIDIFile1.MsgText
  668.                 Case 6 'Marker
  669.                     MessageList.AddItem "Marker " & Hex$(MIDIFile1.Data1) & " : " & MIDIFile1.MsgText
  670.                 Case 7 'Cue point
  671.                     MessageList.AddItem "Cue point " & Hex$(MIDIFile1.Data1) & " : " & MIDIFile1.MsgText
  672. '                Case &H51 '81
  673.                     MessageList.AddItem Str(MIDIFile1.Time) & " Tempo " & Int(60000000 / MIDIFile1.Tempo)
  674. '                    Label4.Caption = Int(60000000 / MIDIFile1.Tempo)
  675. '                    HSliderTempo.Value = Int(60000000 / MIDIFile1.Tempo)
  676. '                Case &H58 '88
  677.                     MessageList.AddItem Str(MIDIFile1.Time) & " Time Signature " & MIDIFile1.Numerator + "/" & (MIDIFile1.Denominator ^ 2)
  678. '                    lblTimeSig.Caption = MIDIFile1.Numerator & "/" & MIDIFile1.Denominator ^ 2
  679.                 Case Else
  680.                     MessageList.AddItem "Sysex " & Hex$(MIDIFile1.Data1)
  681.             End Select
  682.         Else
  683.             MessageList.AddItem Hex$(MIDIFile1.Message)
  684.         End If
  685.     Next
  686.     Screen.MousePointer = 0
  687. End Sub
  688.  
  689. Sub DisplayTrackList ()
  690.     Dim m As Integer
  691.     Dim t As Integer
  692.  
  693.     TrackList.Clear
  694.     For t = 1 To MIDIFile1.NumberOfTracks
  695.         TrackList.AddItem GetTrackName(t)
  696.     Next
  697.  
  698.     GetTempoChanges
  699.     GetTimeSignature
  700. End Sub
  701.  
  702. Function FetchNumber (s As String) As Integer
  703.     If (HexCheck.Value) Then
  704.         FetchNumber = Val("&H" & s)
  705.     Else
  706.         FetchNumber = Val(s)
  707.     End If
  708. End Function
  709.  
  710. Sub FileExit_Click ()
  711.     If (OkToExit()) Then
  712.         End
  713.     End If
  714. End Sub
  715.  
  716. Sub FileNew_Click ()
  717.     Dim wRtn As Integer
  718.     Dim ts As Variant
  719.  
  720.     If (fModified) Then
  721.         wRtn = MsgBox("Discard changes to current file?", 36)
  722.         If (wRtn <> 6) Then
  723.             Exit Sub
  724.         End If
  725.     End If
  726.     MIDIFile1.Filename = "Untitled.mid"
  727.     Form1.Caption = "Untitled.mid"
  728.     On Error Resume Next
  729.     ts = FileDateTime("Untitled.mid")
  730.     wRtn = Err
  731.     On Error GoTo 0
  732.     If (wRtn = 0) Then
  733.         wRtn = MsgBox("Untitled.mid already exists, do you want to recreate it?", 36)
  734.         If (wRtn = 6) Then
  735.             Kill "Untitled.mid"
  736.             wRtn = 1
  737.         Else
  738.             wRtn = 0
  739.         End If
  740.     Else
  741.         wRtn = 1
  742.     End If
  743.     If (wRtn) Then
  744.         MIDIFile1.Action = MIDIFILE_CREATE
  745.         MIDIFile1.Action = MIDIFILE_SAVE
  746.     Else
  747.         MIDIFile1.Action = MIDIFILE_OPEN
  748.     End If
  749.     DisplayTrackList
  750.     TrackList.ListIndex = 0
  751.     fModified = 0
  752. End Sub
  753.  
  754. Sub FileOpen_Click ()
  755.     On Error Resume Next
  756.     CMDialog1.DialogTitle = "Open MIDI File"
  757.     CMDialog1.Flags = &H1000&
  758.     CMDialog1.Action = 1
  759.     If (Err) Then
  760.         Exit Sub
  761.     End If
  762.     MIDIFile1.Filename = CMDialog1.Filename
  763.     MIDIFile1.Action = MIDIFILE_OPEN
  764.     DisplayTrackList
  765.     TrackList.ListIndex = 1
  766.     fModified = 0
  767. End Sub
  768.  
  769. Sub FileSave_Click ()
  770.     MIDIFile1.Action = MIDIFILE_SAVE
  771. End Sub
  772.  
  773. Sub FileSaveAs_Click ()
  774.     If (SaveAs()) Then
  775.         Form1.Caption = CMDialog1.Filename
  776.     End If
  777. End Sub
  778.  
  779. Sub Form_Load ()
  780.     Dim i As Integer
  781.  
  782.     '
  783.     ' Fill output device combo box
  784.     '
  785.     For i = -1 To MIDIOutput1.DeviceCount - 1
  786.         MIDIOutput1.DeviceID = i
  787.         OutputDevCombo.AddItem MIDIOutput1.ProductName
  788.     Next
  789.     '
  790.     ' Select first in list
  791.     '
  792.     MIDIOutput1.DeviceID = -1
  793.     OutputDevCombo.ListIndex = 0
  794.     '
  795.     ' Fill input device combo box
  796.     '
  797.     For i = 0 To MIDIInput1.DeviceCount - 1
  798.         MIDIInput1.DeviceID = i
  799.         InputDevCombo.AddItem MIDIInput1.ProductName
  800.     Next
  801.     '
  802.     ' Select first in list
  803.     '
  804.     MIDIInput1.DeviceID = -1
  805.     InputDevCombo.ListIndex = 0
  806.     fModified = 0
  807.     Form1.Show
  808.     HighLight Picture1, 1
  809.     HighLight Picture2, 1
  810.     HighLight Frame1, 1
  811.     HighLight Frame2, 1
  812. End Sub
  813.  
  814. Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer)
  815.     If (OkToExit() <> True) Then
  816.         Cancel = True
  817.     End If
  818. End Sub
  819.  
  820. Sub Form_Unload (Cancel As Integer)
  821.     CloseOutputDevice
  822.     CloseInputDevice
  823. End Sub
  824.  
  825. Function FormatNumber (n As Long) As String
  826.     If (HexCheck.Value) Then
  827.         FormatNumber = Hex$(n)
  828.     Else
  829.         FormatNumber = Format(n)
  830.     End If
  831. End Function
  832.  
  833. Sub GetTempoChanges ()
  834.     Dim m As Integer
  835.     Dim TempoChangeCount As Integer
  836.     Dim CurrentTime As Long
  837.     
  838.     Screen.MousePointer = 11
  839.  
  840.     TotalTempoChanges = 0
  841.  
  842.     MIDIFile1.TrackNumber = 1
  843.  
  844.     For m = 1 To MIDIFile1.MessageCount
  845.         MIDIFile1.MessageNumber = m
  846.         
  847.         'Meta Tempo Event
  848.         If (MIDIFile1.Message = 255) And MIDIFile1.Data1 = &H51 Then
  849.             'Keep track of the total number of tempo changes in this MIDI file
  850.             TotalTempoChanges = TotalTempoChanges + 1
  851.  
  852.             'This is the tempo
  853.             TempoSetting(TotalTempoChanges) = MIDIFile1.Tempo
  854.  
  855.             'Calculate msPerTick at this tempo -- this is used when playing back MIDI input
  856.             msPerTick(TotalTempoChanges) = TempoSetting(TotalTempoChanges) / 1000 / MIDIFile1.TicksPerQuarterNote
  857.  
  858.             'Calculate ticksPerMs at this tempo -- this is used when recoding MIDI input
  859.             ticksPerMs(TotalTempoChanges) = MIDIFile1.TicksPerQuarterNote / TempoSetting(TotalTempoChanges) * 1000
  860.                     
  861.             TempoTime(TotalTempoChanges) = TempoTime(TotalTempoChanges - 1) + MIDIFile1.Time * msPerTick(TotalTempoChanges)
  862.  
  863.             'Display the first tempo
  864.             LabelTempo.Caption = Int(60000000 / TempoSetting(1))
  865.             'Display TickperQuarterNote
  866.             LabelTicks.Caption = MIDIFile1.TicksPerQuarterNote
  867.         End If
  868.     Next
  869. End Sub
  870.  
  871. Sub GetTimeSignature ()
  872.     Dim m As Integer
  873.  
  874.     MIDIFile1.TrackNumber = 1
  875.  
  876.     For m = 1 To MIDIFile1.MessageCount
  877.         MIDIFile1.MessageNumber = m
  878.         
  879.         'Meta Event Key Signature
  880.         If (MIDIFile1.Message = 255) And MIDIFile1.Data1 = &H58 Then
  881.             LabelTimeSignature.Caption = MIDIFile1.Numerator & "/" & MIDIFile1.Denominator ^ 2
  882.         End If
  883.     Next
  884. End Sub
  885.  
  886. Function GetTrackName (Track As Integer) As String
  887.     Dim i As Integer
  888.  
  889.     MIDIFile1.TrackNumber = Track
  890.  
  891.     For i = 1 To MIDIFile1.MessageCount
  892.         MIDIFile1.MessageNumber = i
  893.         '
  894.         'Meta Event
  895.         '
  896.         If (MIDIFile1.Message = 255) And MIDIFile1.Data1 = 3 Then
  897.             If (MIDIFile1.MsgText = "") Then
  898.                 GetTrackName = "Track" & Str(Track) & " (null)"
  899.             Else
  900.                 GetTrackName = MIDIFile1.MsgText
  901.             End If
  902.             Exit Function
  903.         End If
  904.     Next
  905.     GetTrackName = "Track" & Str(Track)
  906. End Function
  907.  
  908. Sub InputDevCombo_Click ()
  909.     '
  910.     ' Stop and Close currently opened device (if any)
  911.     '
  912.     StopRecording
  913. End Sub
  914.  
  915. Sub MessageList_Click ()
  916.     MIDIFile1.MessageNumber = MessageList.ListIndex + 1
  917.     TimeEdit.Text = FormatNumber(CLng(MIDIFile1.Time))
  918.     MessageEdit.Text = FormatNumber(CLng(MIDIFile1.Message))
  919.     Data1Edit.Text = FormatNumber(CLng(MIDIFile1.Data1))
  920.     Data2Edit.Text = FormatNumber(CLng(MIDIFile1.Data2))
  921.     BufferEdit.Text = MIDIFile1.Buffer
  922.     MsgTextEdit.Text = MIDIFile1.MsgText
  923.  
  924. End Sub
  925.  
  926. Sub MIDIInput1_Message ()
  927.     Dim InMessage As Integer
  928.     Dim InData1 As Integer
  929.     Dim InData2 As Integer
  930.     Dim Y As Integer
  931.  
  932.     If (fGotFirst = False) Then
  933.         InPreviousTime = MIDIInput1.Time
  934.         fGotFirst = True
  935.         fRecording = True
  936.     End If
  937.     '
  938.     'This do while loop allows you to take all the messages that are
  939.     'waiting in the message queue.
  940.     '
  941.     Do While MIDIInput1.MessageCount > 0
  942.         '
  943.         'This is the incoming MIDI data
  944.         '
  945.         InMessage = MIDIInput1.Message
  946.         InData1 = MIDIInput1.Data1
  947.         InData2 = MIDIInput1.Data2
  948.         '
  949.         ' Copy input to output?
  950.         '
  951.         If (MidiThruCheck.Value) Then
  952.             '
  953.             'Tell MIDIOutput1 to send the MIDI data
  954.             '
  955.             MIDIOutput1.Message = InMessage
  956.             MIDIOutput1.Data1 = InData1
  957.             MIDIOutput1.Data2 = InData2
  958.             MIDIOutput1.Action = MIDIOUT_SEND
  959.         End If
  960.  
  961.         If (InsertRecordingCheck.Value) And InMessage < 254 Then
  962.             
  963.             ' Copy message parameters
  964.             MIDIFile1.Message = InMessage
  965.             MIDIFile1.Data1 = InData1
  966.             MIDIFile1.Data2 = InData2
  967.             
  968.             ' Calculate time in ticks
  969.             InCurrentTime = MIDIInput1.Time
  970.             MIDIFile1.Time = (InCurrentTime - InPreviousTime) * msPerTick(1)
  971.             InPreviousTime = InCurrentTime
  972.  
  973.             ' insert message into MIDI file
  974.             MIDIFile1.Action = MIDIFILE_INSERT_MESSAGE
  975.         End If
  976.         '
  977.         'Remove the MIDI data from the MIDI IN queue
  978.         '
  979.         MIDIInput1.Action = MIDIIN_REMOVE
  980.     Loop
  981. End Sub
  982.  
  983. Sub MIDIOutput1_Error (ErrorCode As Integer, ErrorMessage As String)
  984.     MsgBox ErrorMessage
  985. End Sub
  986.  
  987. Sub MIDIOutput1_MessageSent (MessageTag As Long)
  988.     LabelTempo.Caption = Str$(Int(60000000 / TempoSetting(MessageTag)))
  989. End Sub
  990.  
  991. Sub MIDIOutput1_QueueEmpty ()
  992.     StopPlay
  993. End Sub
  994.  
  995. Function OkToExit () As Integer
  996.     Dim wRtn As Integer
  997.  
  998.     If (fModified) Then
  999.         wRtn = MsgBox("Save file before exiting?", 36)
  1000.         If (wRtn = 6) Then
  1001.             If (MIDIFile1.Filename = "Untitled.mid") Then
  1002.                 If (SaveAs() = False) Then
  1003.                    OkToExit = False
  1004.                    Exit Function
  1005.                 End If
  1006.             Else
  1007.                 MIDIFile1.Action = MIDIFILE_SAVE
  1008.             End If
  1009.         End If
  1010.     End If
  1011.     OkToExit = True
  1012. End Function
  1013.  
  1014. Sub OpenInputDevice ()
  1015.     MIDIInput1.DeviceID = InputDevCombo.ListIndex
  1016.     MIDIInput1.Action = MIDIIN_OPEN
  1017. End Sub
  1018.  
  1019. Sub OpenOutputDevice ()
  1020.     '
  1021.     ' Restore defaults
  1022.     '
  1023.     PlaybackRateSlider = 0
  1024.     '
  1025.     ' Open selected device
  1026.     '
  1027.     MIDIOutput1.DeviceID = OutputDevCombo.ListIndex - 1
  1028.     MIDIOutput1.Action = MIDIOUT_OPEN
  1029.     '
  1030.     ' Save volume if opened ok
  1031.     '
  1032.     If (MIDIOutput1.HMidiDevice <> 0) Then
  1033.         '
  1034.         ' If device supports volume, save starting volume
  1035.         '
  1036.         If (MIDIOutput1.HasLRVolume) Then
  1037.             lVolume = MIDIOutput1.VolumeLeft
  1038.             rVolume = MIDIOutput1.VolumeRight
  1039.         ElseIf (MIDIOutput1.HasVolume) Then
  1040.             lVolume = MIDIOutput1.VolumeLeft
  1041.         End If
  1042.     End If
  1043. End Sub
  1044.  
  1045. Sub OutputDevCombo_Click ()
  1046.     '
  1047.     ' Stop and Close currently opened device (if any)
  1048.     '
  1049.     StopPlay
  1050. End Sub
  1051.  
  1052. Sub QueueTrack (Track As Integer)
  1053.     Dim m As Integer
  1054.     Dim n As Integer
  1055.     Dim i As Double
  1056.     Dim TempoChangeCount As Integer
  1057.     Dim msTickTime As Integer
  1058.     Dim TimerTagCount As Integer
  1059.     
  1060.     PreviousTime = 0
  1061.     CurrentTime = 0
  1062.     TimerTagCount = 0
  1063.     
  1064.     Screen.MousePointer = 11
  1065.  
  1066.     TempoChangeCount = 1
  1067.     
  1068.     MIDIFile1.TrackNumber = Track
  1069.  
  1070.     For m = 1 To MIDIFile1.MessageCount
  1071.         MIDIFile1.MessageNumber = m
  1072.         
  1073.         'Meta Event
  1074.         If (MIDIFile1.Message <> 255) Then
  1075.             'PreviousTime is = to the total ms into the song for this track
  1076.             '
  1077.             'Int(MIDIFile1.Time * msPerTick(TempoChangeCount)) is = to the total ms
  1078.             'that need to pass before playing the next event
  1079.             '
  1080.             CurrentTime = PreviousTime + MIDIFile1.Time * msPerTick(TempoChangeCount)
  1081.  
  1082.             'if the time value of TempoTime(TempoChangeCount) is less than or equal
  1083.             'to the current time, a tempo change is needed.
  1084.             '
  1085.             'Note that msPerTick() is set in Sub GetTempoChanges () at the time a new MIDI
  1086.             'file is loaded.
  1087.             If TotalTempoChanges > TempoChangeCount And TempoTime(TempoChangeCount) <= CurrentTime Then
  1088.  
  1089.                 'Use MessageTag property in MIDIOutput1 fire an event at the time the
  1090.                 'tempo changes so that we can change the LabelTempo.Caption.
  1091.                 '
  1092.                 'See: Sub MIDIOutput1_MessageSent for actual updating of LabelTempo.Caption
  1093.                 MIDIOutput1.MessageTag = TempoChangeCount
  1094.                 TempoChangeCount = TempoChangeCount + 1
  1095.             End If
  1096.             
  1097.             'Time in ms to send this event
  1098.             MIDIOutput1.Time = CurrentTime
  1099.  
  1100.             'Keep track of the CurrentTime for the next event we queue
  1101.             PreviousTime = CurrentTime
  1102.             
  1103.             ' Put message data in control
  1104.             MIDIOutput1.Message = MIDIFile1.Message
  1105.             MIDIOutput1.Data1 = MIDIFile1.Data1
  1106.             MIDIOutput1.Data2 = MIDIFile1.Data2
  1107.             
  1108.             ' Add to output queue
  1109.             MIDIOutput1.Action = MIDIOUT_QUEUE
  1110.         End If
  1111.     DoEvents
  1112.     Next
  1113.     Screen.MousePointer = 0
  1114. End Sub
  1115.  
  1116. Function SaveAs () As Integer
  1117.     CMDialog1.DialogTitle = "Save MIDI File As"
  1118.     On Error Resume Next
  1119.     CMDialog1.Flags = &H2&
  1120.     CMDialog1.Action = 2
  1121.     If (Err) Then
  1122.         SaveAs = False
  1123.         Exit Function
  1124.     End If
  1125.     On Error GoTo 0
  1126.     MIDIFile1.Filename = CMDialog1.Filename
  1127.     MIDIFile1.Action = MIDIFILE_SAVE_AS
  1128.     SaveAs = True
  1129. End Function
  1130.  
  1131. Sub StartPlay ()
  1132.     OpenOutputDevice
  1133.     MIDIOutput1.Action = MIDIOUT_START
  1134.     CmdPlay.Enabled = False
  1135.     CmdRecord.Enabled = False
  1136.     CmdStop.Enabled = True
  1137. End Sub
  1138.  
  1139. Sub StartRecording ()
  1140.     OpenInputDevice
  1141.  
  1142.     MIDIInput1.Action = MIDIIN_START
  1143.     'InPreviousTime = MIDIInput1.Time
  1144.  
  1145.     CmdPlay.Enabled = False
  1146.     CmdRecord.Enabled = False
  1147.     CmdStop.Enabled = True
  1148.     fGotFirst = False
  1149. End Sub
  1150.  
  1151. Sub StopPlay ()
  1152.     MIDIOutput1.Action = MIDIOUT_STOP
  1153.     CloseOutputDevice
  1154.     CmdPlay.Enabled = True
  1155.     CmdRecord.Enabled = True
  1156.     CmdStop.Enabled = False
  1157. End Sub
  1158.  
  1159. Sub StopRecording ()
  1160.     MIDIInput1.Action = MIDIIN_STOP
  1161.     CloseInputDevice
  1162.     If (MidiThruCheck) Then
  1163.         CloseOutputDevice
  1164.     End If
  1165.     CmdPlay.Enabled = True
  1166.     CmdRecord.Enabled = True
  1167.     CmdStop.Enabled = False
  1168.     fRecording = False
  1169.     If (InsertRecordingCheck) Then
  1170.         DisplayTrack (TrackList.ListIndex + 1)
  1171.     End If
  1172. End Sub
  1173.  
  1174. Sub TrackList_Click ()
  1175.     DisplayTrack (TrackList.ListIndex + 1)
  1176. End Sub
  1177.  
  1178.