Option Strict Off
Option Explicit On
Imports CarlsMidiTools
Imports System.Runtime.InteropServices

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private insts() As String = Instrument.OutDeviceNames
    Friend WithEvents cmbGM As System.Windows.Forms.ComboBox
    Friend WithEvents btnReplay As System.Windows.Forms.Button
    Private WithEvents Inst As New CarlsMidiTools.Instrument

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents btnRandTone As System.Windows.Forms.Button
    Friend WithEvents Timer As System.Windows.Forms.Timer
    Friend WithEvents butExit As System.Windows.Forms.Button
    Friend WithEvents btnRandToneDur As System.Windows.Forms.Button
    Friend WithEvents btnRandHarm As System.Windows.Forms.Button
    Friend WithEvents btnRandHarmDur As System.Windows.Forms.Button
    Friend WithEvents cb00 As System.Windows.Forms.CheckBox
    Friend WithEvents cb01 As System.Windows.Forms.CheckBox
    Friend WithEvents btnPlayGrid As System.Windows.Forms.Button
    Friend WithEvents cb02 As System.Windows.Forms.CheckBox
    Friend WithEvents cb03 As System.Windows.Forms.CheckBox
    Friend WithEvents cb04 As System.Windows.Forms.CheckBox
    Friend WithEvents cb05 As System.Windows.Forms.CheckBox
    Friend WithEvents cb06 As System.Windows.Forms.CheckBox
    Friend WithEvents cb16 As System.Windows.Forms.CheckBox
    Friend WithEvents cb15 As System.Windows.Forms.CheckBox
    Friend WithEvents cb14 As System.Windows.Forms.CheckBox
    Friend WithEvents cb13 As System.Windows.Forms.CheckBox
    Friend WithEvents cb12 As System.Windows.Forms.CheckBox
    Friend WithEvents cb11 As System.Windows.Forms.CheckBox
    Friend WithEvents cb10 As System.Windows.Forms.CheckBox
    Friend WithEvents cb26 As System.Windows.Forms.CheckBox
    Friend WithEvents cb25 As System.Windows.Forms.CheckBox
    Friend WithEvents cb24 As System.Windows.Forms.CheckBox
    Friend WithEvents cb23 As System.Windows.Forms.CheckBox
    Friend WithEvents cb22 As System.Windows.Forms.CheckBox
    Friend WithEvents cb21 As System.Windows.Forms.CheckBox
    Friend WithEvents cb20 As System.Windows.Forms.CheckBox
    Friend WithEvents cb36 As System.Windows.Forms.CheckBox
    Friend WithEvents cb35 As System.Windows.Forms.CheckBox
    Friend WithEvents cb34 As System.Windows.Forms.CheckBox
    Friend WithEvents cb33 As System.Windows.Forms.CheckBox
    Friend WithEvents cb32 As System.Windows.Forms.CheckBox
    Friend WithEvents cb31 As System.Windows.Forms.CheckBox
    Friend WithEvents cb30 As System.Windows.Forms.CheckBox
    Friend WithEvents cb46 As System.Windows.Forms.CheckBox
    Friend WithEvents cb45 As System.Windows.Forms.CheckBox
    Friend WithEvents cb44 As System.Windows.Forms.CheckBox
    Friend WithEvents cb43 As System.Windows.Forms.CheckBox
    Friend WithEvents cb42 As System.Windows.Forms.CheckBox
    Friend WithEvents cb41 As System.Windows.Forms.CheckBox
    Friend WithEvents cb40 As System.Windows.Forms.CheckBox
    Friend WithEvents cb56 As System.Windows.Forms.CheckBox
    Friend WithEvents cb55 As System.Windows.Forms.CheckBox
    Friend WithEvents cb54 As System.Windows.Forms.CheckBox
    Friend WithEvents cb53 As System.Windows.Forms.CheckBox
    Friend WithEvents cb52 As System.Windows.Forms.CheckBox
    Friend WithEvents cb51 As System.Windows.Forms.CheckBox
    Friend WithEvents cb50 As System.Windows.Forms.CheckBox
    Friend WithEvents cb66 As System.Windows.Forms.CheckBox
    Friend WithEvents cb65 As System.Windows.Forms.CheckBox
    Friend WithEvents cb64 As System.Windows.Forms.CheckBox
    Friend WithEvents cb63 As System.Windows.Forms.CheckBox
    Friend WithEvents cb62 As System.Windows.Forms.CheckBox
    Friend WithEvents cb61 As System.Windows.Forms.CheckBox
    Friend WithEvents cb60 As System.Windows.Forms.CheckBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.btnRandTone = New System.Windows.Forms.Button
        Me.Timer = New System.Windows.Forms.Timer(Me.components)
        Me.butExit = New System.Windows.Forms.Button
        Me.btnRandToneDur = New System.Windows.Forms.Button
        Me.btnRandHarm = New System.Windows.Forms.Button
        Me.btnRandHarmDur = New System.Windows.Forms.Button
        Me.cb00 = New System.Windows.Forms.CheckBox
        Me.cb01 = New System.Windows.Forms.CheckBox
        Me.btnPlayGrid = New System.Windows.Forms.Button
        Me.cb02 = New System.Windows.Forms.CheckBox
        Me.cb03 = New System.Windows.Forms.CheckBox
        Me.cb04 = New System.Windows.Forms.CheckBox
        Me.cb05 = New System.Windows.Forms.CheckBox
        Me.cb06 = New System.Windows.Forms.CheckBox
        Me.cb16 = New System.Windows.Forms.CheckBox
        Me.cb15 = New System.Windows.Forms.CheckBox
        Me.cb14 = New System.Windows.Forms.CheckBox
        Me.cb13 = New System.Windows.Forms.CheckBox
        Me.cb12 = New System.Windows.Forms.CheckBox
        Me.cb11 = New System.Windows.Forms.CheckBox
        Me.cb10 = New System.Windows.Forms.CheckBox
        Me.cb26 = New System.Windows.Forms.CheckBox
        Me.cb25 = New System.Windows.Forms.CheckBox
        Me.cb24 = New System.Windows.Forms.CheckBox
        Me.cb23 = New System.Windows.Forms.CheckBox
        Me.cb22 = New System.Windows.Forms.CheckBox
        Me.cb21 = New System.Windows.Forms.CheckBox
        Me.cb20 = New System.Windows.Forms.CheckBox
        Me.cb36 = New System.Windows.Forms.CheckBox
        Me.cb35 = New System.Windows.Forms.CheckBox
        Me.cb34 = New System.Windows.Forms.CheckBox
        Me.cb33 = New System.Windows.Forms.CheckBox
        Me.cb32 = New System.Windows.Forms.CheckBox
        Me.cb31 = New System.Windows.Forms.CheckBox
        Me.cb30 = New System.Windows.Forms.CheckBox
        Me.cb46 = New System.Windows.Forms.CheckBox
        Me.cb45 = New System.Windows.Forms.CheckBox
        Me.cb44 = New System.Windows.Forms.CheckBox
        Me.cb43 = New System.Windows.Forms.CheckBox
        Me.cb42 = New System.Windows.Forms.CheckBox
        Me.cb41 = New System.Windows.Forms.CheckBox
        Me.cb40 = New System.Windows.Forms.CheckBox
        Me.cb56 = New System.Windows.Forms.CheckBox
        Me.cb55 = New System.Windows.Forms.CheckBox
        Me.cb54 = New System.Windows.Forms.CheckBox
        Me.cb53 = New System.Windows.Forms.CheckBox
        Me.cb52 = New System.Windows.Forms.CheckBox
        Me.cb51 = New System.Windows.Forms.CheckBox
        Me.cb50 = New System.Windows.Forms.CheckBox
        Me.cb66 = New System.Windows.Forms.CheckBox
        Me.cb65 = New System.Windows.Forms.CheckBox
        Me.cb64 = New System.Windows.Forms.CheckBox
        Me.cb63 = New System.Windows.Forms.CheckBox
        Me.cb62 = New System.Windows.Forms.CheckBox
        Me.cb61 = New System.Windows.Forms.CheckBox
        Me.cb60 = New System.Windows.Forms.CheckBox
        Me.cmbGM = New System.Windows.Forms.ComboBox
        Me.btnReplay = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'btnRandTone
        '
        Me.btnRandTone.Location = New System.Drawing.Point(16, 16)
        Me.btnRandTone.Name = "btnRandTone"
        Me.btnRandTone.Size = New System.Drawing.Size(150, 30)
        Me.btnRandTone.TabIndex = 0
        Me.btnRandTone.Text = "Random Tones"
        '
        'butExit
        '
        Me.butExit.BackColor = System.Drawing.Color.Red
        Me.butExit.Location = New System.Drawing.Point(376, 224)
        Me.butExit.Name = "butExit"
        Me.butExit.Size = New System.Drawing.Size(72, 32)
        Me.butExit.TabIndex = 1
        Me.butExit.Text = "EXIT"
        Me.butExit.UseVisualStyleBackColor = False
        '
        'btnRandToneDur
        '
        Me.btnRandToneDur.Location = New System.Drawing.Point(16, 56)
        Me.btnRandToneDur.Name = "btnRandToneDur"
        Me.btnRandToneDur.Size = New System.Drawing.Size(150, 30)
        Me.btnRandToneDur.TabIndex = 2
        Me.btnRandToneDur.Text = "Random Tones & Durations"
        '
        'btnRandHarm
        '
        Me.btnRandHarm.Location = New System.Drawing.Point(16, 96)
        Me.btnRandHarm.Name = "btnRandHarm"
        Me.btnRandHarm.Size = New System.Drawing.Size(150, 30)
        Me.btnRandHarm.TabIndex = 3
        Me.btnRandHarm.Text = "Transition Limits"
        '
        'btnRandHarmDur
        '
        Me.btnRandHarmDur.Location = New System.Drawing.Point(16, 136)
        Me.btnRandHarmDur.Name = "btnRandHarmDur"
        Me.btnRandHarmDur.Size = New System.Drawing.Size(150, 30)
        Me.btnRandHarmDur.TabIndex = 4
        Me.btnRandHarmDur.Text = "Transition Limits & Random Durations"
        '
        'cb00
        '
        Me.cb00.AutoSize = True
        Me.cb00.Checked = True
        Me.cb00.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cb00.Location = New System.Drawing.Point(191, 25)
        Me.cb00.Name = "cb00"
        Me.cb00.Size = New System.Drawing.Size(15, 14)
        Me.cb00.TabIndex = 6
        Me.cb00.UseVisualStyleBackColor = True
        '
        'cb01
        '
        Me.cb01.AutoSize = True
        Me.cb01.Checked = True
        Me.cb01.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cb01.Location = New System.Drawing.Point(212, 24)
        Me.cb01.Name = "cb01"
        Me.cb01.Size = New System.Drawing.Size(29, 17)
        Me.cb01.TabIndex = 7
        Me.cb01.Text = " "
        Me.cb01.UseVisualStyleBackColor = True
        '
        'btnPlayGrid
        '
        Me.btnPlayGrid.Location = New System.Drawing.Point(16, 174)
        Me.btnPlayGrid.Name = "btnPlayGrid"
        Me.btnPlayGrid.Size = New System.Drawing.Size(150, 30)
        Me.btnPlayGrid.TabIndex = 8
        Me.btnPlayGrid.Text = "Play grid"
        Me.btnPlayGrid.UseVisualStyleBackColor = True
        '
        'cb02
        '
        Me.cb02.AutoSize = True
        Me.cb02.Location = New System.Drawing.Point(233, 24)
        Me.cb02.Name = "cb02"
        Me.cb02.Size = New System.Drawing.Size(29, 17)
        Me.cb02.TabIndex = 9
        Me.cb02.Text = " "
        Me.cb02.UseVisualStyleBackColor = True
        '
        'cb03
        '
        Me.cb03.AutoSize = True
        Me.cb03.Location = New System.Drawing.Point(257, 24)
        Me.cb03.Name = "cb03"
        Me.cb03.Size = New System.Drawing.Size(29, 17)
        Me.cb03.TabIndex = 10
        Me.cb03.Text = " "
        Me.cb03.UseVisualStyleBackColor = True
        '
        'cb04
        '
        Me.cb04.AutoSize = True
        Me.cb04.Location = New System.Drawing.Point(278, 24)
        Me.cb04.Name = "cb04"
        Me.cb04.Size = New System.Drawing.Size(29, 17)
        Me.cb04.TabIndex = 11
        Me.cb04.Text = " "
        Me.cb04.UseVisualStyleBackColor = True
        '
        'cb05
        '
        Me.cb05.AutoSize = True
        Me.cb05.Location = New System.Drawing.Point(302, 24)
        Me.cb05.Name = "cb05"
        Me.cb05.Size = New System.Drawing.Size(29, 17)
        Me.cb05.TabIndex = 12
        Me.cb05.Text = " "
        Me.cb05.UseVisualStyleBackColor = True
        '
        'cb06
        '
        Me.cb06.AutoSize = True
        Me.cb06.Location = New System.Drawing.Point(325, 24)
        Me.cb06.Name = "cb06"
        Me.cb06.Size = New System.Drawing.Size(29, 17)
        Me.cb06.TabIndex = 13
        Me.cb06.Text = " "
        Me.cb06.UseVisualStyleBackColor = True
        '
        'cb16
        '
        Me.cb16.AutoSize = True
        Me.cb16.Location = New System.Drawing.Point(325, 47)
        Me.cb16.Name = "cb16"
        Me.cb16.Size = New System.Drawing.Size(29, 17)
        Me.cb16.TabIndex = 20
        Me.cb16.Text = " "
        Me.cb16.UseVisualStyleBackColor = True
        '
        'cb15
        '
        Me.cb15.AutoSize = True
        Me.cb15.Location = New System.Drawing.Point(302, 47)
        Me.cb15.Name = "cb15"
        Me.cb15.Size = New System.Drawing.Size(29, 17)
        Me.cb15.TabIndex = 19
        Me.cb15.Text = " "
        Me.cb15.UseVisualStyleBackColor = True
        '
        'cb14
        '
        Me.cb14.AutoSize = True
        Me.cb14.Location = New System.Drawing.Point(278, 47)
        Me.cb14.Name = "cb14"
        Me.cb14.Size = New System.Drawing.Size(29, 17)
        Me.cb14.TabIndex = 18
        Me.cb14.Text = " "
        Me.cb14.UseVisualStyleBackColor = True
        '
        'cb13
        '
        Me.cb13.AutoSize = True
        Me.cb13.Location = New System.Drawing.Point(257, 47)
        Me.cb13.Name = "cb13"
        Me.cb13.Size = New System.Drawing.Size(29, 17)
        Me.cb13.TabIndex = 17
        Me.cb13.Text = " "
        Me.cb13.UseVisualStyleBackColor = True
        '
        'cb12
        '
        Me.cb12.AutoSize = True
        Me.cb12.Checked = True
        Me.cb12.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cb12.Location = New System.Drawing.Point(233, 47)
        Me.cb12.Name = "cb12"
        Me.cb12.Size = New System.Drawing.Size(29, 17)
        Me.cb12.TabIndex = 16
        Me.cb12.Text = " "
        Me.cb12.UseVisualStyleBackColor = True
        '
        'cb11
        '
        Me.cb11.AutoSize = True
        Me.cb11.Checked = True
        Me.cb11.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cb11.Location = New System.Drawing.Point(212, 47)
        Me.cb11.Name = "cb11"
        Me.cb11.Size = New System.Drawing.Size(29, 17)
        Me.cb11.TabIndex = 15
        Me.cb11.Text = " "
        Me.cb11.UseVisualStyleBackColor = True
        '
        'cb10
        '
        Me.cb10.AutoSize = True
        Me.cb10.Checked = True
        Me.cb10.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cb10.Location = New System.Drawing.Point(191, 48)
        Me.cb10.Name = "cb10"
        Me.cb10.Size = New System.Drawing.Size(15, 14)
        Me.cb10.TabIndex = 14
        Me.cb10.UseVisualStyleBackColor = True
        '
        'cb26
        '
        Me.cb26.AutoSize = True
        Me.cb26.Location = New System.Drawing.Point(325, 70)
        Me.cb26.Name = "cb26"
        Me.cb26.Size = New System.Drawing.Size(29, 17)
        Me.cb26.TabIndex = 27
        Me.cb26.Text = " "
        Me.cb26.UseVisualStyleBackColor = True
        '
        'cb25
        '
        Me.cb25.AutoSize = True
        Me.cb25.Location = New System.Drawing.Point(302, 70)
        Me.cb25.Name = "cb25"
        Me.cb25.Size = New System.Drawing.Size(29, 17)
        Me.cb25.TabIndex = 26
        Me.cb25.Text = " "
        Me.cb25.UseVisualStyleBackColor = True
        '
        'cb24
        '
        Me.cb24.AutoSize = True
        Me.cb24.Location = New System.Drawing.Point(278, 70)
        Me.cb24.Name = "cb24"
        Me.cb24.Size = New System.Drawing.Size(29, 17)
        Me.cb24.TabIndex = 25
        Me.cb24.Text = " "
        Me.cb24.UseVisualStyleBackColor = True
        '
        'cb23
        '
        Me.cb23.AutoSize = True
        Me.cb23.Checked = True
        Me.cb23.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cb23.Location = New System.Drawing.Point(257, 70)
        Me.cb23.Name = "cb23"
        Me.cb23.Size = New System.Drawing.Size(29, 17)
        Me.cb23.TabIndex = 24
        Me.cb23.Text = " "
        Me.cb23.UseVisualStyleBackColor = True
        '
        'cb22
        '
        Me.cb22.AutoSize = True
        Me.cb22.Checked = True
        Me.cb22.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cb22.Location = New System.Drawing.Point(233, 70)
        Me.cb22.Name = "cb22"
        Me.cb22.Size = New System.Drawing.Size(29, 17)
        Me.cb22.TabIndex = 23
        Me.cb22.Text = " "
        Me.cb22.UseVisualStyleBackColor = True
        '
        'cb21
        '
        Me.cb21.AutoSize = True
        Me.cb21.Checked = True
        Me.cb21.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cb21.Location = New System.Drawing.Point(212, 70)
        Me.cb21.Name = "cb21"
        Me.cb21.Size = New System.Drawing.Size(29, 17)
        Me.cb21.TabIndex = 22
        Me.cb21.Text = " "
        Me.cb21.UseVisualStyleBackColor = True
        '
        'cb20
        '
        Me.cb20.AutoSize = True
        Me.cb20.Location = New System.Drawing.Point(191, 71)
        Me.cb20.Name = "cb20"
        Me.cb20.Size = New System.Drawing.Size(15, 14)
        Me.cb20.TabIndex = 21
        Me.cb20.UseVisualStyleBackColor = True
        '
        'cb36
        '
        Me.cb36.AutoSize = True
        Me.cb36.Location = New System.Drawing.Point(325, 90)
        Me.cb36.Name = "cb36"
        Me.cb36.Size = New System.Drawing.Size(29, 17)
        Me.cb36.TabIndex = 34
        Me.cb36.Text = " "
        Me.cb36.UseVisualStyleBackColor = True
        '
        'cb35
        '
        Me.cb35.AutoSize = True
        Me.cb35.Location = New System.Drawing.Point(302, 90)
        Me.cb35.Name = "cb35"
        Me.cb35.Size = New System.Drawing.Size(29, 17)
        Me.cb35.TabIndex = 33
        Me.cb35.Text = " "
        Me.cb35.UseVisualStyleBackColor = True
        '
        'cb34
        '
        Me.cb34.AutoSize = True
        Me.cb34.Checked = True
        Me.cb34.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cb34.Location = New System.Drawing.Point(278, 90)
        Me.cb34.Name = "cb34"
        Me.cb34.Size = New System.Drawing.Size(29, 17)
        Me.cb34.TabIndex = 32
        Me.cb34.Text = " "
        Me.cb34.UseVisualStyleBackColor = True
        '
        'cb33
        '
        Me.cb33.AutoSize = True
        Me.cb33.Checked = True
        Me.cb33.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cb33.Location = New System.Drawing.Point(257, 90)
        Me.cb33.Name = "cb33"
        Me.cb33.Size = New System.Drawing.Size(29, 17)
        Me.cb33.TabIndex = 31
        Me.cb33.Text = " "
        Me.cb33.UseVisualStyleBackColor = True
        '
        'cb32
        '
        Me.cb32.AutoSize = True
        Me.cb32.Checked = True
        Me.cb32.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cb32.Location = New System.Drawing.Point(233, 90)
        Me.cb32.Name = "cb32"
        Me.cb32.Size = New System.Drawing.Size(29, 17)
        Me.cb32.TabIndex = 30
        Me.cb32.Text = " "
        Me.cb32.UseVisualStyleBackColor = True
        '
        'cb31
        '
        Me.cb31.AutoSize = True
        Me.cb31.Location = New System.Drawing.Point(212, 90)
        Me.cb31.Name = "cb31"
        Me.cb31.Size = New System.Drawing.Size(29, 17)
        Me.cb31.TabIndex = 29
        Me.cb31.Text = " "
        Me.cb31.UseVisualStyleBackColor = True
        '
        'cb30
        '
        Me.cb30.AutoSize = True
        Me.cb30.Location = New System.Drawing.Point(191, 91)
        Me.cb30.Name = "cb30"
        Me.cb30.Size = New System.Drawing.Size(15, 14)
        Me.cb30.TabIndex = 28
        Me.cb30.UseVisualStyleBackColor = True
        '
        'cb46
        '
        Me.cb46.AutoSize = True
        Me.cb46.Location = New System.Drawing.Point(325, 113)
        Me.cb46.Name = "cb46"
        Me.cb46.Size = New System.Drawing.Size(29, 17)
        Me.cb46.TabIndex = 41
        Me.cb46.Text = " "
        Me.cb46.UseVisualStyleBackColor = True
        '
        'cb45
        '
        Me.cb45.AutoSize = True
        Me.cb45.Checked = True
        Me.cb45.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cb45.Location = New System.Drawing.Point(302, 113)
        Me.cb45.Name = "cb45"
        Me.cb45.Size = New System.Drawing.Size(29, 17)
        Me.cb45.TabIndex = 40
        Me.cb45.Text = " "
        Me.cb45.UseVisualStyleBackColor = True
        '
        'cb44
        '
        Me.cb44.AutoSize = True
        Me.cb44.Checked = True
        Me.cb44.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cb44.Location = New System.Drawing.Point(278, 113)
        Me.cb44.Name = "cb44"
        Me.cb44.Size = New System.Drawing.Size(29, 17)
        Me.cb44.TabIndex = 39
        Me.cb44.Text = " "
        Me.cb44.UseVisualStyleBackColor = True
        '
        'cb43
        '
        Me.cb43.AutoSize = True
        Me.cb43.Checked = True
        Me.cb43.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cb43.Location = New System.Drawing.Point(257, 113)
        Me.cb43.Name = "cb43"
        Me.cb43.Size = New System.Drawing.Size(29, 17)
        Me.cb43.TabIndex = 38
        Me.cb43.Text = " "
        Me.cb43.UseVisualStyleBackColor = True
        '
        'cb42
        '
        Me.cb42.AutoSize = True
        Me.cb42.Location = New System.Drawing.Point(233, 113)
        Me.cb42.Name = "cb42"
        Me.cb42.Size = New System.Drawing.Size(29, 17)
        Me.cb42.TabIndex = 37
        Me.cb42.Text = " "
        Me.cb42.UseVisualStyleBackColor = True
        '
        'cb41
        '
        Me.cb41.AutoSize = True
        Me.cb41.Location = New System.Drawing.Point(212, 113)
        Me.cb41.Name = "cb41"
        Me.cb41.Size = New System.Drawing.Size(29, 17)
        Me.cb41.TabIndex = 36
        Me.cb41.Text = " "
        Me.cb41.UseVisualStyleBackColor = True
        '
        'cb40
        '
        Me.cb40.AutoSize = True
        Me.cb40.Location = New System.Drawing.Point(191, 114)
        Me.cb40.Name = "cb40"
        Me.cb40.Size = New System.Drawing.Size(15, 14)
        Me.cb40.TabIndex = 35
        Me.cb40.UseVisualStyleBackColor = True
        '
        'cb56
        '
        Me.cb56.AutoSize = True
        Me.cb56.Checked = True
        Me.cb56.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cb56.Location = New System.Drawing.Point(325, 136)
        Me.cb56.Name = "cb56"
        Me.cb56.Size = New System.Drawing.Size(29, 17)
        Me.cb56.TabIndex = 48
        Me.cb56.Text = " "
        Me.cb56.UseVisualStyleBackColor = True
        '
        'cb55
        '
        Me.cb55.AutoSize = True
        Me.cb55.Checked = True
        Me.cb55.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cb55.Location = New System.Drawing.Point(302, 136)
        Me.cb55.Name = "cb55"
        Me.cb55.Size = New System.Drawing.Size(29, 17)
        Me.cb55.TabIndex = 47
        Me.cb55.Text = " "
        Me.cb55.UseVisualStyleBackColor = True
        '
        'cb54
        '
        Me.cb54.AutoSize = True
        Me.cb54.Checked = True
        Me.cb54.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cb54.Location = New System.Drawing.Point(278, 136)
        Me.cb54.Name = "cb54"
        Me.cb54.Size = New System.Drawing.Size(29, 17)
        Me.cb54.TabIndex = 46
        Me.cb54.Text = " "
        Me.cb54.UseVisualStyleBackColor = True
        '
        'cb53
        '
        Me.cb53.AutoSize = True
        Me.cb53.Location = New System.Drawing.Point(257, 136)
        Me.cb53.Name = "cb53"
        Me.cb53.Size = New System.Drawing.Size(29, 17)
        Me.cb53.TabIndex = 45
        Me.cb53.Text = " "
        Me.cb53.UseVisualStyleBackColor = True
        '
        'cb52
        '
        Me.cb52.AutoSize = True
        Me.cb52.Location = New System.Drawing.Point(233, 136)
        Me.cb52.Name = "cb52"
        Me.cb52.Size = New System.Drawing.Size(29, 17)
        Me.cb52.TabIndex = 44
        Me.cb52.Text = " "
        Me.cb52.UseVisualStyleBackColor = True
        '
        'cb51
        '
        Me.cb51.AutoSize = True
        Me.cb51.Location = New System.Drawing.Point(212, 136)
        Me.cb51.Name = "cb51"
        Me.cb51.Size = New System.Drawing.Size(29, 17)
        Me.cb51.TabIndex = 43
        Me.cb51.Text = " "
        Me.cb51.UseVisualStyleBackColor = True
        '
        'cb50
        '
        Me.cb50.AutoSize = True
        Me.cb50.Location = New System.Drawing.Point(191, 137)
        Me.cb50.Name = "cb50"
        Me.cb50.Size = New System.Drawing.Size(15, 14)
        Me.cb50.TabIndex = 42
        Me.cb50.UseVisualStyleBackColor = True
        '
        'cb66
        '
        Me.cb66.AutoSize = True
        Me.cb66.Checked = True
        Me.cb66.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cb66.Location = New System.Drawing.Point(325, 159)
        Me.cb66.Name = "cb66"
        Me.cb66.Size = New System.Drawing.Size(29, 17)
        Me.cb66.TabIndex = 55
        Me.cb66.Text = " "
        Me.cb66.UseVisualStyleBackColor = True
        '
        'cb65
        '
        Me.cb65.AutoSize = True
        Me.cb65.Checked = True
        Me.cb65.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cb65.Location = New System.Drawing.Point(302, 159)
        Me.cb65.Name = "cb65"
        Me.cb65.Size = New System.Drawing.Size(29, 17)
        Me.cb65.TabIndex = 54
        Me.cb65.Text = " "
        Me.cb65.UseVisualStyleBackColor = True
        '
        'cb64
        '
        Me.cb64.AutoSize = True
        Me.cb64.Location = New System.Drawing.Point(278, 159)
        Me.cb64.Name = "cb64"
        Me.cb64.Size = New System.Drawing.Size(29, 17)
        Me.cb64.TabIndex = 53
        Me.cb64.Text = " "
        Me.cb64.UseVisualStyleBackColor = True
        '
        'cb63
        '
        Me.cb63.AutoSize = True
        Me.cb63.Location = New System.Drawing.Point(257, 159)
        Me.cb63.Name = "cb63"
        Me.cb63.Size = New System.Drawing.Size(29, 17)
        Me.cb63.TabIndex = 52
        Me.cb63.Text = " "
        Me.cb63.UseVisualStyleBackColor = True
        '
        'cb62
        '
        Me.cb62.AutoSize = True
        Me.cb62.Location = New System.Drawing.Point(233, 159)
        Me.cb62.Name = "cb62"
        Me.cb62.Size = New System.Drawing.Size(29, 17)
        Me.cb62.TabIndex = 51
        Me.cb62.Text = " "
        Me.cb62.UseVisualStyleBackColor = True
        '
        'cb61
        '
        Me.cb61.AutoSize = True
        Me.cb61.Location = New System.Drawing.Point(212, 159)
        Me.cb61.Name = "cb61"
        Me.cb61.Size = New System.Drawing.Size(29, 17)
        Me.cb61.TabIndex = 50
        Me.cb61.Text = " "
        Me.cb61.UseVisualStyleBackColor = True
        '
        'cb60
        '
        Me.cb60.AutoSize = True
        Me.cb60.Location = New System.Drawing.Point(191, 160)
        Me.cb60.Name = "cb60"
        Me.cb60.Size = New System.Drawing.Size(15, 14)
        Me.cb60.TabIndex = 49
        Me.cb60.UseVisualStyleBackColor = True
        '
        'cmbGM
        '
        Me.cmbGM.FormattingEnabled = True
        Me.cmbGM.Location = New System.Drawing.Point(192, 197)
        Me.cmbGM.Name = "cmbGM"
        Me.cmbGM.Size = New System.Drawing.Size(138, 21)
        Me.cmbGM.TabIndex = 57
        '
        'btnReplay
        '
        Me.btnReplay.Location = New System.Drawing.Point(16, 210)
        Me.btnReplay.Name = "btnReplay"
        Me.btnReplay.Size = New System.Drawing.Size(150, 30)
        Me.btnReplay.TabIndex = 58
        Me.btnReplay.Text = "Replay"
        Me.btnReplay.UseVisualStyleBackColor = True
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(464, 273)
        Me.Controls.Add(Me.btnReplay)
        Me.Controls.Add(Me.cmbGM)
        Me.Controls.Add(Me.cb66)
        Me.Controls.Add(Me.cb65)
        Me.Controls.Add(Me.cb64)
        Me.Controls.Add(Me.cb63)
        Me.Controls.Add(Me.cb62)
        Me.Controls.Add(Me.cb61)
        Me.Controls.Add(Me.cb60)
        Me.Controls.Add(Me.cb56)
        Me.Controls.Add(Me.cb55)
        Me.Controls.Add(Me.cb54)
        Me.Controls.Add(Me.cb53)
        Me.Controls.Add(Me.cb52)
        Me.Controls.Add(Me.cb51)
        Me.Controls.Add(Me.cb50)
        Me.Controls.Add(Me.cb46)
        Me.Controls.Add(Me.cb45)
        Me.Controls.Add(Me.cb44)
        Me.Controls.Add(Me.cb43)
        Me.Controls.Add(Me.cb42)
        Me.Controls.Add(Me.cb41)
        Me.Controls.Add(Me.cb40)
        Me.Controls.Add(Me.cb36)
        Me.Controls.Add(Me.cb35)
        Me.Controls.Add(Me.cb34)
        Me.Controls.Add(Me.cb33)
        Me.Controls.Add(Me.cb32)
        Me.Controls.Add(Me.cb31)
        Me.Controls.Add(Me.cb30)
        Me.Controls.Add(Me.cb26)
        Me.Controls.Add(Me.cb25)
        Me.Controls.Add(Me.cb24)
        Me.Controls.Add(Me.cb23)
        Me.Controls.Add(Me.cb22)
        Me.Controls.Add(Me.cb21)
        Me.Controls.Add(Me.cb20)
        Me.Controls.Add(Me.cb16)
        Me.Controls.Add(Me.cb15)
        Me.Controls.Add(Me.cb14)
        Me.Controls.Add(Me.cb13)
        Me.Controls.Add(Me.cb12)
        Me.Controls.Add(Me.cb11)
        Me.Controls.Add(Me.cb10)
        Me.Controls.Add(Me.cb06)
        Me.Controls.Add(Me.cb05)
        Me.Controls.Add(Me.cb04)
        Me.Controls.Add(Me.cb03)
        Me.Controls.Add(Me.cb02)
        Me.Controls.Add(Me.btnPlayGrid)
        Me.Controls.Add(Me.cb01)
        Me.Controls.Add(Me.cb00)
        Me.Controls.Add(Me.btnRandHarmDur)
        Me.Controls.Add(Me.btnRandHarm)
        Me.Controls.Add(Me.btnRandToneDur)
        Me.Controls.Add(Me.butExit)
        Me.Controls.Add(Me.btnRandTone)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    ' Global variables
    Const PI As Double = 3.14159265358979
    Dim Tone(25) As Double
    Dim Major() As Integer = {0, 2, 4, 5, 7, 9, 11, 12, 14, 16, 17, 19, 21, 23, 24}
    Dim Minor() As Integer = {0, 2, 3, 5, 7, 9, 10, 12, 14, 15, 17, 19, 21, 22, 24}
    Dim Harmonics() As Integer = {0, 4, 7, 12, 16, 19, 24}

    Dim cbArray(7, 7) As CheckBox
    Dim Notes(100) As Integer, Durs(100) As Double, posNote As Integer

    Private Sub frmMain_Load(ByVal eventSender As System.Object, _
        ByVal eventArgs As System.EventArgs) Handles MyBase.Load
        Dim i As Integer

        ' Setup tones and scale
        cbArray(0, 0) = cb00
        cbArray(0, 1) = cb01
        cbArray(0, 2) = cb02
        cbArray(0, 3) = cb03
        cbArray(0, 4) = cb04
        cbArray(0, 5) = cb05
        cbArray(0, 6) = cb06
        cbArray(1, 0) = cb10
        cbArray(1, 1) = cb11
        cbArray(1, 2) = cb12
        cbArray(1, 3) = cb13
        cbArray(1, 4) = cb14
        cbArray(1, 5) = cb15
        cbArray(1, 6) = cb16
        cbArray(2, 0) = cb20
        cbArray(2, 1) = cb21
        cbArray(2, 2) = cb22
        cbArray(2, 3) = cb23
        cbArray(2, 4) = cb24
        cbArray(2, 5) = cb25
        cbArray(2, 6) = cb26
        cbArray(3, 0) = cb30
        cbArray(3, 1) = cb31
        cbArray(3, 2) = cb32
        cbArray(3, 3) = cb33
        cbArray(3, 4) = cb34
        cbArray(3, 5) = cb35
        cbArray(3, 6) = cb36
        cbArray(4, 0) = cb40
        cbArray(4, 1) = cb41
        cbArray(4, 2) = cb42
        cbArray(4, 3) = cb43
        cbArray(4, 4) = cb44
        cbArray(4, 5) = cb45
        cbArray(4, 6) = cb46
        cbArray(5, 0) = cb50
        cbArray(5, 1) = cb51
        cbArray(5, 2) = cb52
        cbArray(5, 3) = cb53
        cbArray(5, 4) = cb54
        cbArray(5, 5) = cb55
        cbArray(5, 6) = cb56
        cbArray(6, 0) = cb60
        cbArray(6, 1) = cb61
        cbArray(6, 2) = cb62
        cbArray(6, 3) = cb63
        cbArray(6, 4) = cb64
        cbArray(6, 5) = cb65
        cbArray(6, 6) = cb66

        ' Setup instrument list
        For i = 0 To 127
            cmbGM.Items.Add(Inst.GMInstrumentNames(i))
        Next
        cmbGM.Text = cmbGM.Items(0)

        ' Open instrument
        With Inst
            .OutputDeviceName = insts(0)
            .OutputChannel = 0
            .Open()
            .PatchNumber = 0
            .Volume = 127
        End With

        Randomize()

    End Sub

    Private Sub cmbGM_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbGM.SelectedIndexChanged
        Inst.ChangePatchGM(cmbGM.Text)
    End Sub

    Private Sub playTone(ByVal Dur As Double, ByVal Freq As Integer)
        Notes(posNote) = Freq
        Durs(posNote) = Dur
        posNote = posNote + 1
        Inst.PlayNote(60 + Freq, 100)
        System.Threading.Thread.Sleep(Dur * 1000)
        Inst.AllNotesOff()
    End Sub

    Private Sub butExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butExit.Click
        End
    End Sub

    Private Sub btnRandTone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRandTone.Click
        Dim i As Integer
        Dim r As Integer
        posNote = 0
        For i = 1 To 8
            r = Math.Floor(Rnd() * 15)
            playTone(0.25, Major(r))
        Next i
    End Sub

    Private Sub btnRandToneDur_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRandToneDur.Click
        Dim i As Integer
        Dim r As Integer, d As Integer
        posNote = 0
        For i = 1 To 8
            r = Math.Floor(Rnd() * 7)
            d = Math.Floor(Rnd() * 2 + 1)
            playTone(d * 0.125, Harmonics(r))
        Next i
    End Sub

    Private Sub btnRandHarm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRandHarm.Click
        Dim i As Integer
        Dim r As Integer, d As Integer
        posNote = 0
        r = Math.Floor(Rnd() * 15)
        For i = 1 To 8
            playTone(0.25, Major(r))
            r = Math.Floor(r + (Rnd() * 5 + 13)) Mod 15
        Next i
    End Sub

    Private Sub btnRandHarmDur_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRandHarmDur.Click
        Dim i As Integer
        Dim r As Integer, d As Integer
        posNote = 0
        r = Math.Floor(Rnd() * 15)
        For i = 1 To 8
            d = Math.Floor(Rnd() * 2 + 1)
            playTone(d * 0.125, Major(r))
            r = Math.Floor(r + Rnd() * 5 + 13) Mod 15
        Next i
    End Sub

    Private Sub btnPlayGrid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlayGrid.Click
        Dim i As Integer
        Dim r0 As Integer, r1 As Integer
        posNote = 0
        r0 = Math.Floor(Rnd() * 7)
        playTone(0.25, Major(r0))
        For i = 1 To 7
            r1 = Math.Floor(Rnd() * 7)
            While (Not (cbArray(r0, r1).Checked))
                r1 = Math.Floor(Rnd() * 7)
            End While
            playTone(0.25, Major(r1))
            r0 = r1
        Next i
    End Sub

    Private Sub btnReplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReplay.Click
        Dim i As Integer
        For i = 0 To posNote - 1
            Inst.PlayNote(60 + Notes(i), 100)
            System.Threading.Thread.Sleep(Durs(i) * 1000)
            Inst.AllNotesOff()
        Next
    End Sub
End Class