
Public Class Form1
    Dim m As New clsMIDI
    Dim note As Integer
    Dim r As Integer
    Dim octiv As Integer = 1

  

    Private Sub playr()
        'MsgBox(r)
        ' r = GetRandomNumber(30, 100)
        ' note = r
        'Me.Refresh()
        'r = GetRandomNumber(0, 127)


        m.PlayMIDINote(note, r)
    End Sub


    Dim objRandom As New System.Random( _
  CType(System.DateTime.Now.Ticks Mod System.Int32.MaxValue, Integer))

    Public Function GetRandomNumber( _
      Optional ByVal Low As Integer = 1, _
      Optional ByVal High As Integer = 100) As Integer
        ' Returns a random number,
        ' between the optional Low and High parameters
        Return objRandom.Next(Low, High + 1)
    End Function


    Private Sub alloff()

        Dim y As Integer

        For y = 0 To 127
            m.PlayMIDINote(y, 0)
        Next
        Button1.BackColor = Color.White
        Button2.BackColor = Color.White
        Button3.BackColor = Color.White
        Button4.BackColor = Color.White
        Button5.BackColor = Color.White
        Button6.BackColor = Color.White
        Button7.BackColor = Color.White
        Button8.BackColor = Color.White
        Button9.BackColor = Color.White
        Button10.BackColor = Color.White
        Button11.BackColor = Color.White
        Button12.BackColor = Color.White
        Button13.BackColor = Color.White
        Button14.BackColor = Color.White
        Button15.BackColor = Color.White
        Button16.BackColor = Color.White
        Button17.BackColor = Color.White
        Button18.BackColor = Color.White
        Button19.BackColor = Color.White
        Button20.BackColor = Color.White
        Button21.BackColor = Color.White
        Button22.BackColor = Color.White
        Button23.BackColor = Color.White
        Button24.BackColor = Color.White
        Button25.BackColor = Color.White
        Button26.BackColor = Color.White
        Button27.BackColor = Color.White
        Button28.BackColor = Color.White
        Button29.BackColor = Color.White
        Button30.BackColor = Color.White
        Button31.BackColor = Color.White
        Button32.BackColor = Color.White
        Button33.BackColor = Color.White
        Button34.BackColor = Color.White
        Button35.BackColor = Color.White
        Button36.BackColor = Color.White

    End Sub



   




    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'set size to screen

        Dim boundWidth As Integer = Screen.PrimaryScreen.Bounds.Width
        Dim boundHeight As Integer = Screen.PrimaryScreen.Bounds.Height
        Me.Height = boundHeight
        Me.Width = boundWidth
        'MsgBox(boundWidth)
        'MsgBox(boundHeight)
        Dim x As Integer = boundWidth - Me.Width
        Dim y As Integer = boundHeight - Me.Height
        Me.Location = New Point(x / 2, y / 2)

    End Sub

    Private Sub Button37_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button37.Click
        alloff()
        End
    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Button1.BackColor = Color.White Then
            Button1.BackColor = Color.DimGray
            note = 1 + octiv * 36
            r = 127
            playr()
        Else
            Button1.BackColor = Color.White
            note = 1 + octiv * 36
            r = 0
            playr()
        End If

    End Sub

    Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Button2.BackColor = Color.White Then
            Button2.BackColor = Color.DimGray
            note = 2 + octiv * 36
            r = 127
            playr()
        Else
            Button2.BackColor = Color.White
            note = 2 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If Button3.BackColor = Color.White Then
            Button3.BackColor = Color.DimGray
            note = 3 + octiv * 36
            r = 127
            playr()
        Else
            Button3.BackColor = Color.White
            note = 3 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button38_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button38.Click
        octiv = octiv + 1
        If octiv > 3 Then octiv = 0
        Button38.Text = octiv.ToString
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Button4.BackColor = Color.White Then
            Button4.BackColor = Color.DimGray
            note = 4 + octiv * 36
            r = 127
            playr()
        Else
            Button4.BackColor = Color.White
            note = 4 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If Button5.BackColor = Color.White Then
            Button5.BackColor = Color.DimGray
            note = 5 + octiv * 36
            r = 127
            playr()
        Else
            Button5.BackColor = Color.White
            note = 5 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If Button6.BackColor = Color.White Then
            Button6.BackColor = Color.DimGray
            note = 6 + octiv * 36
            r = 127
            playr()
        Else
            Button6.BackColor = Color.White
            note = 6 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        If Button7.BackColor = Color.White Then
            Button7.BackColor = Color.DimGray
            note = 7 + octiv * 36
            r = 127
            playr()
        Else
            Button7.BackColor = Color.White
            note = 7 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        If Button8.BackColor = Color.White Then
            Button8.BackColor = Color.DimGray
            note = 8 + octiv * 36
            r = 127
            playr()
        Else
            Button8.BackColor = Color.White
            note = 8 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        If Button9.BackColor = Color.White Then
            Button9.BackColor = Color.DimGray
            note = 9 + octiv * 36
            r = 127
            playr()
        Else
            Button9.BackColor = Color.White
            note = 9 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        If Button10.BackColor = Color.White Then
            Button10.BackColor = Color.DimGray
            note = 10 + octiv * 36
            r = 127
            playr()
        Else
            Button10.BackColor = Color.White
            note = 10 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        If Button11.BackColor = Color.White Then
            Button11.BackColor = Color.DimGray
            note = 11 + octiv * 36
            r = 127
            playr()
        Else
            Button11.BackColor = Color.White
            note = 11 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        If Button12.BackColor = Color.White Then
            Button12.BackColor = Color.DimGray
            note = 12 + octiv * 36
            r = 127
            playr()
        Else
            Button12.BackColor = Color.White
            note = 12 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        If Button13.BackColor = Color.White Then
            Button13.BackColor = Color.DimGray
            note = 13 + octiv * 36
            r = 127
            playr()
        Else
            Button13.BackColor = Color.White
            note = 13 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        If Button14.BackColor = Color.White Then
            Button14.BackColor = Color.DimGray
            note = 14 + octiv * 36
            r = 127
            playr()
        Else
            Button14.BackColor = Color.White
            note = 14 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        If Button15.BackColor = Color.White Then
            Button15.BackColor = Color.DimGray
            note = 15 + octiv * 36
            r = 127
            playr()
        Else
            Button15.BackColor = Color.White
            note = 15 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
        If Button16.BackColor = Color.White Then
            Button16.BackColor = Color.DimGray
            note = 16 + octiv * 36
            r = 127
            playr()
        Else
            Button16.BackColor = Color.White
            note = 16 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
        If Button17.BackColor = Color.White Then
            Button17.BackColor = Color.DimGray
            note = 17 + octiv * 36
            r = 127
            playr()
        Else
            Button17.BackColor = Color.White
            note = 17 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
        If Button18.BackColor = Color.White Then
            Button18.BackColor = Color.DimGray
            note = 18 + octiv * 36
            r = 127
            playr()
        Else
            Button18.BackColor = Color.White
            note = 18 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
        If Button19.BackColor = Color.White Then
            Button19.BackColor = Color.DimGray
            note = 19 + octiv * 36
            r = 127
            playr()
        Else
            Button19.BackColor = Color.White
            note = 19 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click
        If Button20.BackColor = Color.White Then
            Button20.BackColor = Color.DimGray
            note = 20 + octiv * 36
            r = 127
            playr()
        Else
            Button20.BackColor = Color.White
            note = 20 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click
        If Button21.BackColor = Color.White Then
            Button21.BackColor = Color.DimGray
            note = 21 + octiv * 36
            r = 127
            playr()
        Else
            Button21.BackColor = Color.White
            note = 21 + octiv * 36
            r = 0
            playr()
        End If
    End Sub


    Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button22.Click
        If Button22.BackColor = Color.White Then
            Button22.BackColor = Color.DimGray
            note = 22 + octiv * 36
            r = 127
            playr()
        Else
            Button22.BackColor = Color.White
            note = 22 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button23.Click
        If Button23.BackColor = Color.White Then
            Button23.BackColor = Color.DimGray
            note = 23 + octiv * 36
            r = 127
            playr()
        Else
            Button23.BackColor = Color.White
            note = 23 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button24_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button24.Click
        If Button24.BackColor = Color.White Then
            Button24.BackColor = Color.DimGray
            note = 24 + octiv * 36
            r = 127
            playr()
        Else
            Button24.BackColor = Color.White
            note = 24 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button25_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button25.Click
        If Button25.BackColor = Color.White Then
            Button25.BackColor = Color.DimGray
            note = 25 + octiv * 36
            r = 127
            playr()
        Else
            Button25.BackColor = Color.White
            note = 25 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button26_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button26.Click
        If Button26.BackColor = Color.White Then
            Button26.BackColor = Color.DimGray
            note = 26 + octiv * 36
            r = 127
            playr()
        Else
            Button26.BackColor = Color.White
            note = 26 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button27_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button27.Click
        If Button27.BackColor = Color.White Then
            Button27.BackColor = Color.DimGray
            note = 27 + octiv * 36
            r = 127
            playr()
        Else
            Button27.BackColor = Color.White
            note = 27 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button28_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button28.Click
        If Button28.BackColor = Color.White Then
            Button28.BackColor = Color.DimGray
            note = 28 + octiv * 36
            r = 127
            playr()
        Else
            Button28.BackColor = Color.White
            note = 28 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button29_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button29.Click
        If Button29.BackColor = Color.White Then
            Button29.BackColor = Color.DimGray
            note = 29 + octiv * 36
            r = 127
            playr()
        Else
            Button29.BackColor = Color.White
            note = 29 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button39_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button39.Click
        alloff()
    End Sub

    Private Sub Button30_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button30.Click
        If Button30.BackColor = Color.White Then
            Button30.BackColor = Color.DimGray
            note = 30 + octiv * 36
            r = 127
            playr()
        Else
            Button30.BackColor = Color.White
            note = 30 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button31_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button31.Click
        If Button31.BackColor = Color.White Then
            Button31.BackColor = Color.DimGray
            note = 31 + octiv * 36
            r = 127
            playr()
        Else
            Button31.BackColor = Color.White
            note = 31 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button32_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button32.Click
        If Button32.BackColor = Color.White Then
            Button32.BackColor = Color.DimGray
            note = 32 + octiv * 36
            r = 127
            playr()
        Else
            Button32.BackColor = Color.White
            note = 32 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button33_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button33.Click
        If Button33.BackColor = Color.White Then
            Button33.BackColor = Color.DimGray
            note = 33 + octiv * 36
            r = 127
            playr()
        Else
            Button33.BackColor = Color.White
            note = 33 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button34_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button34.Click
        If Button34.BackColor = Color.White Then
            Button34.BackColor = Color.DimGray
            note = 34 + octiv * 36
            r = 127
            playr()
        Else
            Button34.BackColor = Color.White
            note = 34 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button35_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button35.Click
        If Button35.BackColor = Color.White Then
            Button35.BackColor = Color.DimGray
            note = 35 + octiv * 36
            r = 127
            playr()
        Else
            Button35.BackColor = Color.White
            note = 35 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button36_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button36.Click
        If Button36.BackColor = Color.White Then
            Button36.BackColor = Color.DimGray
            note = 36 + octiv * 36
            r = 127
            playr()
        Else
            Button36.BackColor = Color.White
            note = 36 + octiv * 36
            r = 0
            playr()
        End If
    End Sub

    Private Sub Button40_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button40.Click
        Me.WindowState = FormWindowState.Minimized
    End Sub
End Class
