home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Music_Synt2042801162007.psc / Forms / frmMain.frm < prev   
Text File  |  2007-01-17  |  28KB  |  927 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Object = "{C1A8AF28-1257-101B-8FB0-0020AF039CA3}#1.1#0"; "MCI32.OCX"
  4. Begin VB.Form frmMain 
  5.    BackColor       =   &H00FFFFFF&
  6.    Caption         =   "Music Synthesis"
  7.    ClientHeight    =   4110
  8.    ClientLeft      =   60
  9.    ClientTop       =   -4725
  10.    ClientWidth     =   6105
  11.    Icon            =   "frmMain.frx":0000
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   4110
  14.    ScaleWidth      =   6105
  15.    StartUpPosition =   2  'CenterScreen
  16.    WindowState     =   2  'Maximized
  17.    Begin VB.Frame FraSplash 
  18.       BackColor       =   &H00000000&
  19.       Height          =   855
  20.       Left            =   120
  21.       TabIndex        =   11
  22.       Top             =   5400
  23.       Width           =   3015
  24.       Begin VB.Image Splash 
  25.          Height          =   255
  26.          Left            =   120
  27.          Picture         =   "frmMain.frx":08A6
  28.          Stretch         =   -1  'True
  29.          Top             =   240
  30.          Width           =   735
  31.       End
  32.    End
  33.    Begin VB.Frame fraRender 
  34.       BackColor       =   &H00000000&
  35.       Height          =   5175
  36.       Left            =   120
  37.       TabIndex        =   4
  38.       Top             =   120
  39.       Width           =   2535
  40.       Begin VB.CommandButton btnRender 
  41.          BackColor       =   &H00808000&
  42.          Caption         =   "Render and Play"
  43.          Height          =   375
  44.          Left            =   120
  45.          MaskColor       =   &H00808000&
  46.          TabIndex        =   8
  47.          Top             =   4680
  48.          Width           =   1575
  49.       End
  50.       Begin VB.CommandButton btnStop 
  51.          Caption         =   "Stop"
  52.          Enabled         =   0   'False
  53.          Height          =   375
  54.          Left            =   1680
  55.          TabIndex        =   7
  56.          Top             =   4680
  57.          Width           =   735
  58.       End
  59.       Begin VB.ListBox SampleList 
  60.          BackColor       =   &H00000000&
  61.          ForeColor       =   &H00FFFFFF&
  62.          Height          =   1620
  63.          ItemData        =   "frmMain.frx":3B88A
  64.          Left            =   120
  65.          List            =   "frmMain.frx":3B8AF
  66.          TabIndex        =   6
  67.          Top             =   480
  68.          Width           =   2295
  69.       End
  70.       Begin VB.FileListBox lstEnvelope 
  71.          BackColor       =   &H00000000&
  72.          ForeColor       =   &H00FFFFFF&
  73.          Height          =   2040
  74.          Left            =   120
  75.          Pattern         =   "*.env"
  76.          TabIndex        =   5
  77.          Top             =   2520
  78.          Width           =   2295
  79.       End
  80.       Begin VB.Label Label1 
  81.          BackStyle       =   0  'Transparent
  82.          Caption         =   "Envelopes"
  83.          BeginProperty Font 
  84.             Name            =   "MS Sans Serif"
  85.             Size            =   8.25
  86.             Charset         =   0
  87.             Weight          =   700
  88.             Underline       =   0   'False
  89.             Italic          =   0   'False
  90.             Strikethrough   =   0   'False
  91.          EndProperty
  92.          ForeColor       =   &H00E0E0E0&
  93.          Height          =   255
  94.          Index           =   0
  95.          Left            =   120
  96.          TabIndex        =   10
  97.          Top             =   2280
  98.          Width           =   2175
  99.       End
  100.       Begin VB.Label Label1 
  101.          BackStyle       =   0  'Transparent
  102.          Caption         =   "Samples"
  103.          BeginProperty Font 
  104.             Name            =   "MS Sans Serif"
  105.             Size            =   8.25
  106.             Charset         =   0
  107.             Weight          =   700
  108.             Underline       =   0   'False
  109.             Italic          =   0   'False
  110.             Strikethrough   =   0   'False
  111.          EndProperty
  112.          ForeColor       =   &H00E0E0E0&
  113.          Height          =   255
  114.          Index           =   1
  115.          Left            =   120
  116.          TabIndex        =   9
  117.          Top             =   240
  118.          Width           =   2175
  119.       End
  120.    End
  121.    Begin MCI.MMControl MMC 
  122.       Height          =   495
  123.       Left            =   3360
  124.       TabIndex        =   3
  125.       Top             =   5160
  126.       Visible         =   0   'False
  127.       Width           =   3540
  128.       _ExtentX        =   6244
  129.       _ExtentY        =   873
  130.       _Version        =   393216
  131.       DeviceType      =   ""
  132.       FileName        =   ""
  133.    End
  134.    Begin VB.Frame fraEditor 
  135.       BackColor       =   &H00000000&
  136.       Height          =   4695
  137.       Left            =   2760
  138.       TabIndex        =   0
  139.       Top             =   240
  140.       Width           =   3015
  141.       Begin VB.HScrollBar HScroll 
  142.          Height          =   375
  143.          LargeChange     =   20
  144.          Left            =   960
  145.          Max             =   180
  146.          TabIndex        =   2
  147.          Top             =   1920
  148.          Width           =   855
  149.       End
  150.       Begin VB.CommandButton btnZoom 
  151.          Caption         =   "Zoom"
  152.          Height          =   375
  153.          Left            =   840
  154.          TabIndex        =   1
  155.          Top             =   1320
  156.          Width           =   855
  157.       End
  158.       Begin Synthesis.SeqEditor SeqEditor1 
  159.          Height          =   975
  160.          Left            =   600
  161.          Top             =   240
  162.          Width           =   2055
  163.          _ExtentX        =   3625
  164.          _ExtentY        =   1720
  165.       End
  166.       Begin VB.Image ImgKeyboard 
  167.          Appearance      =   0  'Flat
  168.          Height          =   2175
  169.          Left            =   120
  170.          Picture         =   "frmMain.frx":3B985
  171.          Stretch         =   -1  'True
  172.          Top             =   240
  173.          Width           =   525
  174.       End
  175.    End
  176.    Begin MSComDlg.CommonDialog CD 
  177.       Left            =   3960
  178.       Top             =   5760
  179.       _ExtentX        =   847
  180.       _ExtentY        =   847
  181.       _Version        =   393216
  182.    End
  183.    Begin VB.Menu mnuFile 
  184.       Caption         =   "&File"
  185.       Begin VB.Menu mnuFileNew 
  186.          Caption         =   "&New"
  187.          Shortcut        =   ^N
  188.       End
  189.       Begin VB.Menu mnuFileOpen 
  190.          Caption         =   "&Open..."
  191.          Shortcut        =   ^O
  192.       End
  193.       Begin VB.Menu mnuFileDivider1 
  194.          Caption         =   "-"
  195.       End
  196.       Begin VB.Menu mnuFileSave 
  197.          Caption         =   "&Save"
  198.          Shortcut        =   ^S
  199.       End
  200.       Begin VB.Menu mnuFileSaveAs 
  201.          Caption         =   "Save &As..."
  202.       End
  203.       Begin VB.Menu mnuExport 
  204.          Caption         =   "&Export "
  205.          Begin VB.Menu mnuExport2Midi 
  206.             Caption         =   "As &Midi (SingleTrack)"
  207.             Enabled         =   0   'False
  208.          End
  209.          Begin VB.Menu mnuExport2Wave 
  210.             Caption         =   "As &Wave (16Bit PCM)"
  211.          End
  212.          Begin VB.Menu mnuExport2Text 
  213.             Caption         =   "As &Text"
  214.          End
  215.       End
  216.       Begin VB.Menu mnuFileDivider2 
  217.          Caption         =   "-"
  218.       End
  219.       Begin VB.Menu mnuExit 
  220.          Caption         =   "E&xit"
  221.       End
  222.    End
  223.    Begin VB.Menu mnuOptions 
  224.       Caption         =   "&Options"
  225.       Begin VB.Menu mnuSampleType 
  226.          Caption         =   "Sample Type"
  227.          Begin VB.Menu mnuSampleChoice 
  228.             Caption         =   "PureSine"
  229.             Index           =   0
  230.          End
  231.          Begin VB.Menu mnuSampleChoice 
  232.             Caption         =   "SquareWave"
  233.             Index           =   1
  234.          End
  235.          Begin VB.Menu mnuSampleChoice 
  236.             Caption         =   "WhiteNoise"
  237.             Index           =   2
  238.          End
  239.          Begin VB.Menu mnuSampleChoice 
  240.             Caption         =   "Sawtooth"
  241.             Index           =   3
  242.          End
  243.          Begin VB.Menu mnuSampleChoice 
  244.             Caption         =   "SinePlusNoise"
  245.             Index           =   4
  246.          End
  247.          Begin VB.Menu mnuSampleChoice 
  248.             Caption         =   "SinePlusHarmonics"
  249.             Index           =   5
  250.          End
  251.          Begin VB.Menu mnuSampleChoice 
  252.             Caption         =   "Other1 (Sharp)"
  253.             Index           =   6
  254.          End
  255.          Begin VB.Menu mnuSampleChoice 
  256.             Caption         =   "Other2 (Vibratory)"
  257.             Index           =   7
  258.          End
  259.          Begin VB.Menu mnuSampleChoice 
  260.             Caption         =   "Other3"
  261.             Index           =   8
  262.          End
  263.          Begin VB.Menu mnuSampleChoice 
  264.             Caption         =   "Other4"
  265.             Index           =   9
  266.          End
  267.          Begin VB.Menu mnuSampleChoice 
  268.             Caption         =   "Other5"
  269.             Index           =   10
  270.          End
  271.       End
  272.       Begin VB.Menu mnuEditorColors 
  273.          Caption         =   "Editor Colors"
  274.          Begin VB.Menu mnuOptionColors 
  275.             Caption         =   "Plain &White"
  276.             Index           =   0
  277.          End
  278.          Begin VB.Menu mnuOptionColors 
  279.             Caption         =   "&Black Night"
  280.             Index           =   1
  281.          End
  282.          Begin VB.Menu mnuOptionColors 
  283.             Caption         =   "Chocolate &Brown"
  284.             Index           =   2
  285.          End
  286.          Begin VB.Menu mnuOptionColors 
  287.             Caption         =   "Leaf &Green"
  288.             Index           =   3
  289.          End
  290.       End
  291.       Begin VB.Menu mnuAppColors 
  292.          Caption         =   "App Colors"
  293.          Begin VB.Menu mnuAppColorsOption 
  294.             Caption         =   "Black"
  295.             Index           =   0
  296.          End
  297.          Begin VB.Menu mnuAppColorsOption 
  298.             Caption         =   "Pale Dull Blue"
  299.             Index           =   1
  300.          End
  301.          Begin VB.Menu mnuAppColorsOption 
  302.             Caption         =   "Ink Blue"
  303.             Index           =   2
  304.          End
  305.          Begin VB.Menu mnuAppColorsOption 
  306.             Caption         =   "Brown"
  307.             Index           =   3
  308.          End
  309.          Begin VB.Menu mnuAppColorsOption 
  310.             Caption         =   "Green"
  311.             Index           =   4
  312.          End
  313.          Begin VB.Menu mnuAppColorsOption 
  314.             Caption         =   "Light Brown"
  315.             Index           =   5
  316.          End
  317.          Begin VB.Menu mnuAppColorsOption 
  318.             Caption         =   "Violet"
  319.             Index           =   6
  320.          End
  321.          Begin VB.Menu mnuAppColorsOption 
  322.             Caption         =   "DesignTime Setting"
  323.             Index           =   99
  324.             Visible         =   0   'False
  325.          End
  326.       End
  327.    End
  328.    Begin VB.Menu mnuHelp 
  329.       Caption         =   "&Help"
  330.       Begin VB.Menu mnuLoadDemo 
  331.          Caption         =   "Load &Demo Song"
  332.       End
  333.       Begin VB.Menu mnuShowDemo 
  334.          Caption         =   "Show Demo ..."
  335.          Enabled         =   0   'False
  336.       End
  337.       Begin VB.Menu mnuEnvelopeEditor 
  338.          Caption         =   "Envelope Editor"
  339.          Enabled         =   0   'False
  340.       End
  341.       Begin VB.Menu mnuHelpDivider 
  342.          Caption         =   "-"
  343.       End
  344.       Begin VB.Menu mnuAbout 
  345.          Caption         =   "About ..."
  346.       End
  347.    End
  348. End
  349. Attribute VB_Name = "frmMain"
  350. Attribute VB_GlobalNameSpace = False
  351. Attribute VB_Creatable = False
  352. Attribute VB_PredeclaredId = True
  353. Attribute VB_Exposed = False
  354.  
  355. ' WE ARE USING FOLLOWING CONTROLS
  356. '
  357. ' 1) A MULTIMEDIA CONTOL ON THE FORM O PLAY WAVE FILES
  358. ' 2) COMMONDIALOG FOR FILE/SAVE
  359. ' 2) EDITORCONTOL FOR EDITING OF KEYBOARD EVENTS
  360.  
  361. Const FullNote = 1#
  362. Const ThreeFourthNote = 0.75
  363. Const HalfNote = 0.5
  364. Const QuarterNote = 0.25
  365.  
  366. Dim VisibleRows                 As Integer
  367. Dim TotalEvents                 As Integer
  368. Dim VisibleEvents               As Integer
  369. Dim Column                      As Integer
  370. Dim Row                         As Integer
  371. Dim Period                      As Single
  372. Dim ZoomFactor                  As Integer
  373. Dim BaseMidiKey                 As Integer
  374. Dim TypeOfSample                As Integer
  375. Dim WaveFile                    As String
  376. Dim FileNameOnly                As String
  377.  
  378. Private Sub Form_Load()
  379.     
  380.     SongFile.Saved = True   '\____ MUST BE DONE BEFORE BELOW INITIALISE
  381.     mnuFileNew_Click        '/
  382.     
  383.     TotalEvents = Song.EventCount
  384.     BaseMidiKey = Song.BaseMidiKey
  385.     ZoomFactor = 10
  386.     VisibleEvents = 30
  387.     VisibleRows = 48
  388.         
  389.     SeqEditor1.ColorChoice = bgDarkBlue
  390.     SeqEditor1.Columns = VisibleEvents
  391.     SeqEditor1.Rows = VisibleRows
  392.     SeqEditor1.CursorOn = True          ' PROPERTY BAG CODE IS STILL
  393.     SeqEditor1.NumbersOn = True         ' NOT WRITTEN...SO HAVE TO DO IT RUNTIME
  394.     
  395.     HScroll.LargeChange = VisibleEvents
  396.     HScroll.Max = TotalEvents - VisibleEvents
  397.     CD.InitDir = App.Path & "\Songs" ' OR GET LASTUSE FROM REGISTRY
  398.     lstEnvelope.Path = App.Path & "\Envelopes" ' This is a file listbox
  399.     lstEnvelope.ListIndex = 0
  400.     SampleList.ListIndex = 0
  401.     SampleList_Click
  402.     mnuAppColorsOption_Click 0
  403.    
  404. End Sub
  405.  
  406. Private Sub Form_Resize()
  407.     
  408.     On Error Resume Next ' GoTo ResizeError
  409.    
  410.     MinHeight = 480 * 15: MinWidth = 640 * 15
  411.     If Height < MinHeight Then Height = MinHeight
  412.     If Width < MinWidth Then Width = MinWidth
  413.     
  414.     Gap = 90
  415.     
  416. '   LockWindowUpdate API
  417. '   Disables/Enables drawing. Only one window can be locked at a time.
  418.     
  419.     LockWindowUpdate Me.hWnd
  420.     
  421.     ' RESIZE THE FRAMES
  422.     fraRender.Height = ScaleHeight * 0.75
  423.     fraEditor.Top = fraRender.Top
  424.     fraEditor.Height = fraRender.Height
  425.     FraSplash.Top = fraRender.Height + fraRender.Top
  426.     FraSplash.Height = ScaleHeight - FraSplash.Top - Gap
  427.     fraEditor.Width = ScaleWidth - fraEditor.Left - Gap * 2
  428.     FraSplash.Width = ScaleWidth - FraSplash.Left - Gap * 2
  429.      
  430.     ' CONTROLS ON FIRST FRAME
  431.     'LockWindowUpdate fraRender.hWnd
  432.     'fraRender.Visible = False
  433.     btnRender.Top = fraRender.Height - btnRender.Height - Gap
  434.     btnStop.Top = btnRender.Top
  435.     lstEnvelope.Height = btnRender.Top - lstEnvelope.Top - Gap
  436.     'fraRender.Visible = True
  437.     'LockWindowUpdate 0
  438.     
  439.     ' CONTROLS ON SECOND FRAME
  440.     'LockWindowUpdate fraEditor.hWnd
  441.     btnZoom.Left = ImgKeyboard.Left
  442.     btnZoom.Top = fraEditor.Height - btnZoom.Height - Gap
  443.     HScroll.Top = btnZoom.Top
  444.     HScroll.Left = btnZoom.Left + btnZoom.Width
  445.     HScroll.Width = fraEditor.Width - HScroll.Left - Gap * 2
  446.     ImgKeyboard.Height = btnZoom.Top - ImgKeyboard.Top - Gap * 2
  447.     'SeqEditor1.Visible = False
  448.     SeqEditor1.Top = ImgKeyboard.Top
  449.     SeqEditor1.Height = ImgKeyboard.Height
  450.     SeqEditor1.Left = ImgKeyboard.Left + ImgKeyboard.Width
  451.     SeqEditor1.Width = fraEditor.Width - SeqEditor1.Left - Gap * 2
  452.     'SeqEditor1.Visible = True
  453.     'LockWindowUpdate 0
  454.     
  455.     ' CONTROLS ON THIRD FRAME
  456.     'LockWindowUpdate FraSplash.hWnd
  457.     Splash.Visible = False
  458.     Splash.Left = Gap * 2
  459.     Splash.Height = FraSplash.Height - Splash.Top - Gap * 2
  460.     Splash.Width = FraSplash.Width - Gap * 6
  461.     Splash.Visible = True
  462.     'LockWindowUpdate 0
  463.     
  464. ResizeError:
  465. '   RESIZE ERROR IS NOT CRITICAL IN MOST CASES. WE JUST CONTINUE
  466.     LockWindowUpdate 0
  467.     RefreshEditor
  468.     Move 0, 0
  469.  
  470. End Sub
  471.  
  472. Private Sub mnuAbout_Click()
  473. ' TODO : WILL WRITE A PROPER ABOUT...LATER
  474.     Message = About("NAME") & " by " & About("Author") _
  475.               & vbCrLf & "Version " & About("VERSION")
  476.  
  477.               
  478.     MsgBox Message, , About("title")
  479. End Sub
  480.  
  481. Private Sub mnuAppColorsOption_Click(Index As Integer)
  482.     
  483.     
  484.     
  485.     Select Case Index
  486.     Case 0: ColorChoice = 0             ' Black
  487.     Case 1: ColorChoice = &H80000011    ' Pale DullBlue
  488.     Case 2: ColorChoice = &HC00000      ' InkBlue '&H808000 'Blue
  489.     Case 3: ColorChoice = &H404080      ' Brown
  490.     Case 4: ColorChoice = &H9000&       ' Green
  491.     Case 5: ColorChoice = &H8080&       ' LightBrown
  492.     Case 6: ColorChoice = &HAA7070      ' Violet
  493.     Case 99: ColorChoice = BackColor    ' For Experiment Only
  494.     End Select
  495.     
  496.     BackColor = ColorChoice
  497.     fraRender.BackColor = ColorChoice
  498.     fraEditor.BackColor = ColorChoice
  499.     FraSplash.BackColor = ColorChoice
  500.     
  501.     Static OldChoice
  502.     mnuAppColorsOption(OldChoice).Checked = False
  503.     OldChoice = Index
  504.     mnuAppColorsOption(OldChoice).Checked = True
  505.     
  506. End Sub
  507.  
  508.  
  509. '=========================================================
  510. ' CODING FOR THE EDITOR. EASY :-)
  511. '=========================================================
  512. Private Sub SeqEditor1_LeftClick(Column As Integer, Row As Integer, CellDifference As Single)
  513.  
  514.     SeqEditor1.DrawNote Column, Row, FullNote
  515.     Song.Events(Column).MidiKey = GridMidiConvert(Row)
  516.     Song.Events(Column).Duration = FullNote
  517.     SongFile.Saved = False
  518.  
  519. End Sub
  520.  
  521. Private Sub SeqEditor1_RightClick(Column As Integer, Row As Integer, CellDifference As Single)
  522.  
  523.     SeqEditor1.EraseNote Column, Row
  524.     Song.Events(Column).MidiKey = GridMidiConvert(0)
  525.     Song.Events(Column).Duration = 0
  526.     SongFile.Saved = False
  527.  
  528. End Sub
  529.  
  530. Private Sub SeqEditor1_MouseMove(Button As Integer, Column As Integer, Row As Integer, CellDifference As Single)
  531.  
  532.     If (Button = vbLeftButton) And (SeqEditor1.MouseDownCol = Column) Then
  533.         '--
  534.         Select Case CellDifference
  535.         Case Is < 0.3:      DELTA = QuarterNote
  536.         Case 0.3 To 0.6:    DELTA = HalfNote
  537.         Case 0.6 To 0.8:    DELTA = ThreeFourthNote
  538.         Case Else:          DELTA = FullNote
  539.         End Select
  540.         '--
  541.         SeqEditor1.DrawNote Column, Row, CSng(DELTA)
  542.         Song.Events(Column).MidiKey = GridMidiConvert(Row)
  543.         Song.Events(Column).Duration = DELTA
  544.         SongFile.Saved = False
  545.     End If
  546.  
  547. End Sub
  548.  
  549. '=========================================================
  550. ' MENU ROUTINES FOLLW:
  551. ' ROUTINES TO OPEN,SAVE FILES, ETC
  552. '=========================================================
  553.  
  554. Private Sub mnuFileNew_Click()
  555.     
  556.     VerifySaveCurrentSong
  557.     CreateNewSong
  558.     RefreshEditor
  559.     
  560.     FileNameOnly = "Untitled.sng" ' Dir$(SongFile.Name)
  561.     Caption = About("NAME") & " [" & FileNameOnly & "]"
  562.     HScroll.Value = HScroll.Min
  563.     HScroll_Change
  564.     
  565. End Sub
  566.  
  567. Private Sub mnuFileOpen_Click()
  568.     
  569.     VerifySaveCurrentSong
  570.     LoadSong GetOpenFileName()
  571.     RefreshEditor
  572.     
  573.     FileNameOnly = Dir$(SongFile.Name)
  574.     Caption = About("NAME") & " [" & FileNameOnly & "]"
  575.     HScroll.Value = HScroll.Min
  576.     HScroll_Change
  577.  
  578. End Sub
  579.  
  580.  
  581. Private Sub mnuFileSave_Click()
  582.  
  583. Rem TODO:IF FILE ALREADY EXIST...ASK FOR OVERWRITE PERMISSION
  584.  
  585.     If SongFile.Saved Then Exit Sub ' NO NEED TO SAVE
  586.     
  587.     'If Dir$(SongFile.Name) = "" Then ' IF STILL NOT SAVED
  588.     
  589.     ' IF WE DONT HAVE A NAME GET IT
  590.     If Right(SongFile.Name, 12) = "Untitled.sng" Then
  591.        FileName = GetSaveFileName()
  592.        If FileName = "" Then Exit Sub
  593.        SongFile.Name = FileName
  594.        End If
  595.     SaveSong SongFile.Name
  596.  
  597. End Sub
  598.  
  599. Private Sub mnuFileSaveAs_Click()
  600.  
  601. Rem TODO:IF FILE ALREADY EXIST...ASK FOR OVERWRITE PERMISSION
  602.  
  603.     FileName = GetSaveFileName()
  604.     If FileName = "" Then Exit Sub
  605.     SongFile.Name = FileName
  606.     SaveSong SongFile.Name
  607.     
  608.     FileNameOnly = Dir$(SongFile.Name)
  609.     Caption = About("NAME") & " [" & FileNameOnly & "]"
  610.     
  611.  
  612. End Sub
  613.  
  614. Private Sub mnuOptionColors_Click(Index As Integer)
  615.     SeqEditor1.ColorChoice = Index
  616.     RefreshEditor
  617. End Sub
  618.     
  619. Private Sub mnuExport2Wave_Click()
  620.     Export2Wave
  621. End Sub
  622.  
  623. Private Sub mnuExport2Text_Click()
  624.  
  625. Rem THIS IS A QUICK EXPORT OF THE SONG TO A TEXT FILE _
  626.     TODO:REWRITE TO GIVE USER A CHOICE OF EXPORT FILENAME
  627.  
  628. '   LOCATE LAST NON-ZERO EVENT
  629.     N = GetEventCount
  630.     If N = 0 Then
  631.         Message = "There are no events to Export. Cannot Export"
  632.         MsgBox Message, vbExclamation, "Yups !!"
  633.         Exit Sub
  634.         End If
  635.  
  636. '   WRITE HEADER
  637.     StrLine = String(80, "=")
  638.     txtFile = FreeFile
  639.     FileName = SongFile.Name & "-export.txt"
  640.     Open SongFile.Name & "-export.txt" For Output As #txtFile
  641.     Print #txtFile, StrLine
  642.     Print #txtFile, "Exported From File:"; SongFile.Name
  643.     Print #txtFile, "Date:"; Format$(Date$, "DD MMM,YYYY")
  644.     Print #txtFile, "Event Count:"; N
  645.     Print #txtFile, StrLine
  646.     Print #txtFile,
  647.     Print #txtFile, "Event#"; Tab(10); "MidiKey#"; Tab(25); "Duration"
  648.     Print #txtFile, "-----"; Tab(10); "---------"; Tab(25); "--------"
  649.     
  650. '   EXPORT TO TEXT FILE
  651.     For i = 1 To N
  652.     Print #txtFile, i; _
  653.                     Tab(12); Song.Events(i).MidiKey; _
  654.                     Tab(27); Song.Events(i).Duration
  655.     Next
  656.     Close #txtFile
  657.     Message = "The song has been exported to" & vbCrLf & FileName
  658.     MsgBox Message, vbInformation, "Export"
  659.     
  660. End Sub
  661.  
  662. Private Sub mnuSampleChoice_Click(Index As Integer)
  663.     
  664.     mnuSampleChoice(TypeOfSample).Checked = False
  665.     TypeOfSample = Index
  666.     mnuSampleChoice(TypeOfSample).Checked = True
  667.     SampleList.ListIndex = Index
  668.     
  669. End Sub
  670.  
  671. Private Sub mnuExit_Click()
  672.     End
  673. End Sub
  674.  
  675. Private Sub mnuLoadDemo_Click()
  676.  
  677.     FileName = (App.Path & "\Songs\Demo.sng")
  678.     LoadSong FileName
  679.     RefreshEditor
  680.     
  681.     FileNameOnly = Dir$(SongFile.Name)
  682.     Caption = About("NAME") & " [" & FileNameOnly & "]"
  683.     
  684.     HScroll.Value = HScroll.Min
  685.     HScroll_Change
  686.     
  687. End Sub
  688.  
  689.  
  690. '=========================================================
  691. ' ROUTINES TO PLAY THE WAVE FILE
  692. '=========================================================
  693.  
  694. Sub WavFileLoad(ByVal FileName As String)
  695.  
  696. Rem BEFORE WE 'OPEN' AND 'PLAY' ANOTHER WAVE FILE, WE MUST _
  697.     STOP ANY OPEN FILE THAT IS ALREADY PLAYING. OTHERWISE _
  698.     THE SECOND FILE WONT PLAY
  699.     
  700.     If Dir(FileName) = "" Then
  701.             Message = "Error Loading Rendered Wav File. Can't Play"
  702.             MsgBox Message, , , "Error"
  703.     Else:   MMC.DeviceType = "WAVEAUDIO"
  704.             MMC.Notify = True
  705.             MMC.FileName = FileName
  706.             WavFileStop
  707.             End If
  708.  
  709. End Sub
  710.  
  711. Sub WavFilePlay()
  712.  
  713.     If WaveFile = "" Then
  714.         Message = "Please select a file from the list to be played"
  715.         MsgBox Message, vbExclamation, "Yups !!"
  716.         Exit Sub
  717.         End If
  718.  
  719.     WavFileLoad WaveFile
  720.     SetButtons False, False 'Play=0,Stop=0
  721.     If MMC.Mode = mciModeNotOpen Then MMC.Command = "open"
  722.     If MMC.Mode = mciModePause Then
  723.             MMC.Command = "pause"
  724.     Else:   MMC.Command = "play"
  725.             End If
  726.  
  727.     Do: DoEvents
  728.     Loop Until MMC.Mode = mciModePlay
  729.     SetButtons False, True  'Play=0,Stop=1
  730.  
  731. End Sub
  732.  
  733. Sub WavFilePause()
  734.  
  735.     If MMC.Mode <> mciModePlay Then Exit Sub
  736.     SetButtons False, False  'Play=0,Stop=0
  737.     MMC.Command = "pause"
  738.     Do: DoEvents
  739.     Loop Until MMC.Mode = mciModePause
  740.     SetButtons True, False   'Play=1,Stop=0
  741.   
  742. End Sub
  743. Sub WavFileStop()
  744.  
  745.     SetButtons False, False   'Play=0,Stop=0
  746.     MMC.Command = "stop"
  747.     MMC.Command = "close"
  748.     Do: DoEvents
  749.     Loop Until MMC.Mode = mciModeNotOpen
  750.     SetButtons True, False    'Play=1,Stop=0
  751.     
  752. End Sub
  753.  
  754. Private Sub MMC_Done(NotifyCode As Integer)
  755.     WavFileStop
  756. End Sub
  757.  
  758. Sub SetButtons(valPlay As Boolean, valStop As Boolean)
  759.     btnRender.Enabled = valPlay
  760.     btnStop.Enabled = valStop
  761. End Sub
  762.  
  763. '=========================================================
  764. ' CODING FOR VARIOUS OTHER CONTROLS FOLLOW
  765. '=========================================================
  766.  
  767. Private Sub btnZoom_Click()
  768.     ZoomFactor = -ZoomFactor ' TOGGLE ZoomFactor
  769.     VisibleEvents = VisibleEvents + ZoomFactor
  770.     SeqEditor1.Columns = VisibleEvents
  771.     HScroll.LargeChange = VisibleEvents
  772.     HScroll.Max = TotalEvents - VisibleEvents
  773.     RefreshEditor
  774. End Sub
  775.  
  776. Private Sub HScroll_Change()
  777.     SeqEditor1.LeftCol = HScroll.Value + 1
  778.     RefreshEditor
  779. End Sub
  780.  
  781. Private Sub SampleList_Click()
  782.     mnuSampleChoice(TypeOfSample).Checked = False
  783.     TypeOfSample = SampleList.ListIndex
  784.     mnuSampleChoice(TypeOfSample).Checked = True
  785. End Sub
  786.  
  787. Private Sub btnRender_Click()
  788.     If Export2Wave Then WavFilePlay
  789. End Sub
  790.  
  791. Private Sub btnStop_Click()
  792.     WavFileStop
  793. End Sub
  794.  
  795. '=========================================================
  796. ' VARIOUS OTHER HELPER ROUTINES HERE
  797. '=========================================================
  798. Sub RefreshEditor()
  799.  
  800.     For N = 0 To VisibleEvents - 1
  801.     Column = CInt(N + SeqEditor1.LeftCol)
  802.     Row = GridMidiConvert(Song.Events(Column).MidiKey)
  803.     Period = Song.Events(Column).Duration
  804.     SeqEditor1.DrawNote Column, Row, Period
  805.     Next
  806.  
  807. End Sub
  808.  
  809. Function GridMidiConvert(ByVal Row As Integer) As Integer
  810.  
  811. Rem THIS FUNCTION DOES BOTH INTERCONVERSIONS. _
  812.     SO WE DONT NEED THE FOLLOWING SEPARATE FUNCTIONS
  813.     '--
  814.     'Function Midi2Grid(Row As Integer) As Integer ' same as Grid2Midi
  815.     '    Midi2Grid = BaseMidiKey + VisibleRows - Row
  816.     'End Function
  817.     '--
  818.     'Function Grid2Midi(Row As Integer) As Integer ' same as Midi2Grid
  819.     '    Grid2Midi = BaseMidiKey + VisibleRows - Row
  820.     'End Function
  821.     '--
  822.     
  823.     Select Case Row
  824.     Case 0:    GridMidiConvert = 0
  825.     Case Else: GridMidiConvert = BaseMidiKey + VisibleRows - Row
  826.     End Select
  827.     
  828. End Function
  829.  
  830. Sub VerifySaveCurrentSong()
  831.  
  832. Rem CANNOT USE FOLLOWING -- VB CALCULATES BOTH
  833.     ' SaveIt = (Not (SongFile.Saved)) And UserWants2Save
  834.     ' If Not (SaveIt) Then Exit Sub
  835.     
  836.     If SongFile.Saved Then Exit Sub
  837.     If Not (UserWants2Save) Then Exit Sub
  838.     If SongFile.Name = "" Then SongFile.Name = GetSaveFileName()
  839.     SaveSong SongFile.Name
  840.     
  841. End Sub
  842.  
  843. Function UserWants2Save() As Boolean
  844.     Prompt = "Do you want to save the changes to current file?"
  845.     Answer = MsgBox(Prompt, vbQuestion + vbYesNo)
  846.     UserWants2Save = (Answer = vbYes)
  847. End Function
  848.  
  849. Function GetOpenFileName() As String
  850.     On Error GoTo ErrorHandler:
  851.     
  852.     CD.DialogTitle = "Open"
  853.     CD.CancelError = False
  854.     CD.Filter = "Song File (*.sng)|*.sng"
  855.     CD.Flags = cdlOFNExplorer + cdlOFNFileMustExist
  856.     CD.ShowOpen
  857.     
  858.     If Len(CD.FileName) = 0 Then
  859.             GetOpenFileName = ""
  860.     Else:   GetOpenFileName = CD.FileName
  861.             CD.InitDir = ""
  862.             End If
  863.       
  864. ErrorHandler:
  865.  
  866. End Function
  867.  
  868. Function GetSaveFileName() As String
  869.  
  870.     On Error GoTo ErrorHandler
  871.  
  872.     CD.DialogTitle = "Save"
  873.     CD.CancelError = False      'CD.CancelError = True
  874.     CD.Filter = "Song File (*.sng)|*.sng"
  875.     CD.DefaultExt = "*.sng"
  876.     CD.Flags = cdlOFNHideReadOnly
  877.     CD.ShowSave
  878.     
  879.     If Len(CD.FileName) = 0 Then
  880.             GetSaveFileName = ""
  881.     Else:   GetSaveFileName = CD.FileName
  882.             CD.InitDir = ""
  883.             End If
  884.     
  885. ErrorHandler:
  886.  
  887. End Function
  888.  
  889. Function Export2Wave() As Boolean
  890.  
  891.     NoteCount = GetEventCount
  892.     If NoteCount = 0 Then
  893.         Message = "There is nothing to render." _
  894.                    & vbCrLf & "Please open a *.sng file or" _
  895.                    & vbCrLf & "create some events on the " _
  896.                    & vbCrLf & "editor for rendering."
  897.         MsgBox Message, vbExclamation, "Yups !!"
  898.         Export2Wave = False
  899.         Exit Function
  900.     End If
  901.     '---------------
  902.     'FileNameOnly = Mid$(SongFile.Name, InStrRev(SongFile.Name, "\") + 1) ' TEMP STRING
  903.     FileNameOnly = Dir$(SongFile.Name)
  904.     If FileNameOnly = "" Then FileNameOnly = "Untitled.sng"
  905.     WaveFile = App.Path & "\Renders\" & _
  906.                Replace(FileNameOnly, ".sng", ".wav")
  907.     EnvelopeFile = App.Path & "\Envelopes\" & lstEnvelope.FileName
  908.     '---------------
  909.     MousePointer = 11
  910.     btnRender.Enabled = False   ' DONT WANT USER TO DISTURB US
  911.     tribINGt_Cl  ' DON) DONThen
  912.         MePriMder.Enabled = F fsd Function
  913.     '-0 TDuratior1 d Funct       ue
  914.   on
  915.  
  916. Function -exp ing."
  917.      iem CANNOs
  918.     If Not (UserWanturatior1 d Funct.In ue
  919.   on
  920. Sn).Duration = FullNotngFi' (UserWanturatior1 d FR.Dur        =  nst.ListIndex = Index
  921.     
  922. End Sub
  923.  
  924. Pr.se
  925.   e, False    'Pla's"\'n 
  926. Dse
  927.   e, False    'Pla's