Author Topic: Direct bass : Vb.net (vb2008, vb2010, vb6, vc#, vc++, devC++, delphi, AutoIt)  (Read 161449 times)

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #50 on: 30 Oct '12 - 17:54 »
Sample:ClassCode6:: Writting Code bass Player Functions

Set event scroll eq volume 10 bands (eq1 - eq10)

You must set Properties TrackBar eq  value volume (Min - Max) very bands

TrackBar properties:
1. Maximum = 10
2. Minimum = -10
3. Value = 0

Code: [Select]
Private Sub eq1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles eq1.Scroll
        Try
            UpdateEQ(0, CSng(eq1.Value * -1))
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub eq2_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles eq2.Scroll
        Try
            UpdateEQ(1, CSng(eq2.Value * -1))
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub eq3_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles eq3.Scroll
        Try
            UpdateEQ(2, CSng(eq3.Value * -1))
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub eq4_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles eq4.Scroll
        Try
            UpdateEQ(3, CSng(eq4.Value * -1))
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub eq5_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles eq5.Scroll
        Try
            UpdateEQ(4, CSng(eq5.Value * -1))
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub eq6_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles eq6.Scroll
        Try
            UpdateEQ(5, CSng(eq6.Value * -1))
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub eq7_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles eq7.Scroll
        Try
            UpdateEQ(6, CSng(eq7.Value * -1))
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub eq8_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles eq8.Scroll
        Try
            UpdateEQ(7, CSng(eq8.Value * -1))
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub eq9_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles eq9.Scroll
        Try
            UpdateEQ(8, CSng(eq9.Value * -1))
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub eq10_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles eq10.Scroll
        Try
            UpdateEQ(9, CSng(eq10.Value * -1))
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
« Last Edit: 30 Oct '12 - 17:58 by sak2005 »

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #51 on: 30 Oct '12 - 18:22 »
Get Graphic Visualizer on the PictureBox (with out FFT)
For nBass1.8 only

 nBassVisualizer Function: 2 Options
1. picBoxObj is a PictureBox component to create.
2. TimeSongEnd is Timer component Sync with BassChannelIsActive when song Stopped set state timeEnable = false (Timer.Stop)
Set time Interval = 35

Code: [Select]
Public Function nBassVisualizer(ByVal picBoxObj As PictureBox, ByVal TimeSongEnd As Timer) As Double
        Dim grapReset As Graphics = PictureBox1.CreateGraphics
        Dim bit As Bitmap = New Bitmap(picBoxObj.Width, picBoxObj.Height)
        Dim graph As Graphics = Graphics.FromImage(bit)
        Dim AquaPen As New Pen(Color.Aqua, 4)
        Dim buff(1024) As Single
        Dim X, Y As Integer
        Try
            BASS_ChannelGetData(stream, buff(0), &H80000011)
            For X = 0 To picBoxObj.Width Step 5
                Y = Sqrt(buff(X + 100)) * 1 * 5 * 1 * picBoxObj.Height - 1
                If Y > picBoxObj.Height Then Y = picBoxObj.Height
                graph.DrawLine(AquaPen, X, PictureBox1.Height, X, picBoxObj.Height - Y)
            Next
            picBoxObj.Image = bit
            If BASS_ChannelIsActive(stream) = BASS_ACTIVE_STOPPED Then
                grapReset.Clear(Color.Black)
                TimeSongEnd.Enabled = False
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return X And Y
    End Function
    Public Function Sqrt(ByVal num As Double) As Double
        Try
            Sqrt = num ^ 0.4
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return Sqrt
    End Function
------------------------------------------------------------
Example:
Code: [Select]
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Try
            nBassVisualizer(PictureBox1, Timer1)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
                 
« Last Edit: 31 Oct '12 - 10:00 by sak2005 »

Rouse

  • Posts: 3
Re: Direct bass : Vb.net
« Reply #52 on: 30 Oct '12 - 18:24 »
sak2005 is it possable to get a timeline example made up?

|----|----|----|----|----|..............
0:00                    0:20............ and so on

based on the track length of an mp3?

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #53 on: 31 Oct '12 - 08:32 »
sak2005 is it possable to get a timeline example made up?

|----|----|----|----|----|..............
0:00                    0:20............ and so on

based on the track length of an mp3?

Okay..I'm modifying.

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #54 on: 31 Oct '12 - 15:02 »
Selected bands array code to use. For BassEQ

Code: [Select]
Private fxEQ As Integer() = New Integer(10 - 1) {}
Code: [Select]
Private fxEQ As Integer() = New Integer() {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Code: [Select]
Private fxEQ As Integer()
Public Sub New()
   For i As Integer = 1 To 10
      fxEQ = New Integer(i) {}
   Next i
End Sub

Code: [Select]
Private fxEQ As Integer()
Public Sub New()
   Dim i As Integer = 1   
   Do Until i > 10
      i += 1
      fxEQ = New Integer(i) {}
   Loop
End Sub

Code: [Select]
Private fxEQ As Integer()
Public Sub New()
   Dim i As Integer = 1
   Do While i < 10
      i += 1
      fxEQ = New Integer(i) {}
   Loop
End Sub
« Last Edit: 31 Oct '12 - 17:06 by sak2005 »

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #55 on: 3 Nov '12 - 05:11 »
Get BassUn4Seen EQualizer & Visualizer easy code project Click here

Tip: You must writting code variable operater of the visualizer out of function (Global variable) Peak hold color not work (์No delay) If writting variable is in the function.

Setting properties Timer and Peak hold time delay:Default
Interval = 40
PeakDelay = 20

The Loundness get gain form a eq1 (Maximum gain = 10)

Example:
Code: [Select]
Private spectrum As New Un4seen.Bass.Misc.Visuals
Private Sub VisTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VisTimer.Tick
        PictureBox1.Image = spectrum.CreateSpectrumLinePeak(strm, PictureBox1.Width, PictureBox1.Height, Color.Aqua, Color.DeepSkyBlue, Color.White, Color.Black, 4, 2, 1, 22.5, False, False, True)
End Sub

« Last Edit: 3 Nov '12 - 05:50 by sak2005 »

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #56 on: 4 Nov '12 - 07:41 »
Get code: SongStateNoneStop (1 Option)

Changed itemsList When Song end.

1.CheckBox for state item change noneStop or Not noneStop.

Code: [Select]
Public Sub SongStateNoneStop(ByVal chkBox1 As CheckBox)
        Select Case chkBox1.CheckState
            Case CheckState.Checked
                If Math.Round((Un4seen.Bass.Bass.BASS_ChannelGetPosition(strm) / Un4seen.Bass.Bass.BASS_ChannelGetLength(strm)) * 100) = 100 Then
                    Try
                        ListBox1.SelectedIndex += 1
                        PlayButton.PerformClick()
                    Catch ex As Exception
                        ListBox1.SelectedIndex = 0
                        PlayButton.PerformClick()
                    End Try
                End If
        End Select
    End Sub

Example:
Code: [Select]
Private Sub NoneStopTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NoneStopTimer.Tick
        SongStateNoneStop(CheckBox1)
    End Sub

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #57 on: 4 Nov '12 - 08:18 »
Get code: Selected to Items in the List to remove item.(1 Option)

Set select state item in the list with leftClick

Use ContextMenuStrip component for rightClick confirm to delete item.

1. SongsList. Use ListBox component.

Code: [Select]
Public Sub New()
        MyBase.New()
        InitializeComponent()
        ListBox1.ContextMenuStrip = ContextMenuStrip1
    End Sub
    Public Sub ItemsListClearSelect(ByVal ItemsList As ListBox)
        If ItemsList.SelectedItem = Nothing Then Return
        ItemsList.Items.RemoveAt(ListBox1.SelectedIndex)
    End Sub


Example:
Code: [Select]
Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
        ItemsListClearSelect(ListBox1)
    End Sub
    Private Sub ContextMenuStrip1_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening
        ToolStripMenuItem1.Text = "Clear"
    End Sub

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #58 on: 4 Nov '12 - 09:13 »
Get code: ContextMenuStrip Event Handle (RightClick Menu)

Code: [Select]
   Private conText1 As ContextMenuStrip
    Private toolStrip1 As ToolStripMenuItem
    Public Sub New()
        MyBase.New()
        InitializeComponent()
        conText1 = New ContextMenuStrip()
        toolStrip1 = New ToolStripMenuItem("Clear")
        conText1.Items.Add(toolStrip1)
        ListBox1.ContextMenuStrip = conText1
        AddHandler toolStrip1.Click, AddressOf toolStrip1_Click
    End Sub
    Private Sub toolStrip1_Click(ByVal sender As Object, ByVal e As EventArgs)
        ItemsListClearSelect(ListBox1)
    End Sub
    Public Sub ItemsListClearSelect(ByVal ItemsList As ListBox)
        If ItemsList.SelectedItem = Nothing Then Return
        ItemsList.Items.RemoveAt(ListBox1.SelectedIndex)
    End Sub
« Last Edit: 4 Nov '12 - 09:31 by sak2005 »

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #59 on: 4 Nov '12 - 09:36 »
Get code: AddSongsItemsList Function (ConText Menu)

You not must create object components.

Paste all code on the form edit. Try run now.

Code: [Select]
   Public Class Form1
    Private itemsList As New ListBox
    Private time As New Timer
    Private openFileDLG As New OpenFileDialog
    Private conText1 As New ContextMenuStrip
    Private toolStrip1 As New ToolStripMenuItem("Load")
    Private toolStrip2 As New ToolStripMenuItem("Play")
    Private toolStrip3 As New ToolStripMenuItem("Stop")
    Private tip As New ToolTip
    Private stream As Integer
    Public Sub New()
        MyBase.New()
        InitializeComponent()
        BASS_Init_Register()
        ControlProperties()
        tip.AutomaticDelay = 10
        tip.AutoPopDelay = 5000
        tip.ShowAlways = True
        conText1.Items.AddRange(New ToolStripItem() {toolStrip1, toolStrip2, toolStrip3})
        itemsList.ContextMenuStrip = conText1
        Me.Controls.Add(itemsList)
        Me.Text = "SongsItemsList Sample (RightClick)"
        Me.Size = New Size(300, 200)
        Me.MinimizeBox = False
        Me.MaximizeBox = False
        Me.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink
        Me.CenterToScreen()
        AddHandler itemsList.DoubleClick, AddressOf itemsList_DoubleClick
        AddHandler itemsList.MouseHover, AddressOf itemsList_MouseHover
        AddHandler toolStrip1.Click, AddressOf toolStrip1_Click
        AddHandler toolStrip2.Click, AddressOf toolStrip2_Click
        AddHandler toolStrip3.Click, AddressOf toolStrip3_Click
        AddHandler time.Tick, AddressOf time_Tick
    End Sub
    Public Sub ControlProperties()
        With openFileDLG
            .FileName = Nothing
            .Filter = "Song file(*.mp3)|*.mp3"
        End With
        itemsList.SetBounds(10, 10, 270, 150)
        itemsList.HorizontalScrollbar = True
        End Sub
    Public Sub BASS_AddSongsItemsList()
        If openFileDLG.ShowDialog = Windows.Forms.DialogResult.OK Then
            Un4seen.Bass.Bass.BASS_StreamFree(stream)
            Dim file As String = openFileDLG.FileName
            itemsList.Items.Add(file)
            itemsList.SelectedIndex += 1
            If itemsList.SelectedItem <> Nothing Then
                Dim itemsFile As String = itemsList.SelectedItem.ToString
                stream = Un4seen.Bass.Bass.BASS_StreamCreateFile(itemsFile, 0, 0, Un4seen.Bass.BASSFlag.BASS_DEFAULT)
            End If
        End If
    End Sub
    Public Sub BASS_Init_Register()
        Dim device As Integer = -1
        Dim freq As Integer = 44100
        Dim flags As Un4seen.Bass.BASSInit = Un4seen.Bass.BASSInit.BASS_DEVICE_DEFAULT
        Dim win As System.IntPtr = IntPtr.Zero
        Dim email As String = "xxx@gmail.com"
        Dim registrationKey As String = "2Xxxxxxxxxxxxxx"
        Un4seen.Bass.BassNet.Registration(email, registrationKey)
        Un4seen.Bass.Bass.BASS_Init(device, freq, flags, win)
    End Sub
    Public Sub itemsList_DoubleClick(ByVal sender As Object, ByVal e As EventArgs)
        If stream <> 0 Then
            Un4seen.Bass.Bass.BASS_StreamFree(stream)
            Un4seen.Bass.Bass.BASS_ChannelPlay(stream, True)
            If itemsList.SelectedItem <> Nothing Then
                Dim itemsFile As String = itemsList.SelectedItem.ToString
                stream = Un4seen.Bass.Bass.BASS_StreamCreateFile(itemsFile, 0, 0, Un4seen.Bass.BASSFlag.BASS_DEFAULT)
                If stream <> Nothing Then
                    Un4seen.Bass.Bass.BASS_ChannelPlay(stream, True)
                    time.Enabled = True
            End If
            End If
        End If
    End Sub
    Public Sub toolStrip1_Click(ByVal sender As Object, ByVal e As EventArgs)
        BASS_AddSongsItemsList()
    End Sub
    Public Sub toolStrip2_Click(ByVal sender As Object, ByVal e As EventArgs)
        BASS_SelectIndexItemsCount(stream, itemsList)
        If stream <> Nothing Then
            Un4seen.Bass.Bass.BASS_ChannelPlay(stream, True)
            time.Enabled = True
        End If
    End Sub
    Public Sub toolStrip3_Click(ByVal sender As Object, ByVal e As EventArgs)
        Un4seen.Bass.Bass.BASS_ChannelStop(stream)
    End Sub
    Public Sub itemsList_MouseHover(ByVal sender As Object, ByVal e As EventArgs)
        tip.SetToolTip(itemsList, "DoubleClick items to Playing")
    End Sub
    Public Sub BASS_SelectIndexItemsCount(ByVal handle As Integer, ByVal itemsList As ListBox)
        Un4seen.Bass.Bass.BASS_StreamFree(handle)
        Dim index As Integer = Nothing
        Dim itemsFile As String = Nothing
        For x As Integer = 0 To itemsList.Items.Count - 1
            If itemsList.GetSelected(x) = True Then
                index &= x
                Exit For
            End If
        Next
        Try
            itemsList.SelectedIndex = index
            itemsFile = itemsList.SelectedItem.ToString
            stream = Un4seen.Bass.Bass.BASS_StreamCreateFile(itemsFile, 0, 0, Un4seen.Bass.BASSFlag.BASS_DEFAULT)
        Catch ex As Exception
            MsgBox("pleased load file to the list", 0, "")
        End Try
    End Sub
    Public Sub BASS_percentMousePosition(ByVal tip As ToolTip, ByVal time As Timer)
        Dim pos As Integer = Un4seen.Bass.Bass.BASS_ChannelGetPosition(stream, Un4seen.Bass.BASSMode.BASS_POS_BYTES)
        Dim len As Integer = Un4seen.Bass.Bass.BASS_ChannelGetLength(stream, Un4seen.Bass.BASSMode.BASS_POS_BYTES)
        Dim percent As Integer = Math.Round((pos / len) * 100)
        tip.SetToolTip(itemsList, "Playing.." & percent & "/100")
    End Sub
    Public Sub time_Tick(ByVal sender As Object, ByVal e As EventArgs)
        BASS_percentMousePosition(tip, time)
        If Un4seen.Bass.Bass.BASS_ChannelIsActive(stream) = Un4seen.Bass.BASSActive.BASS_ACTIVE_STOPPED Then
            tip.SetToolTip(itemsList, "Song End")
            time.Enabled = False
        End If
    End Sub
End Class
« Last Edit: 4 Nov '12 - 18:37 by sak2005 »

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #60 on: 5 Nov '12 - 08:43 »
Get code: Fix SpectrumVisualizer Function (Display to use)

Syntax: SpectrumVisualizer(handle, PictureBox)

Code: [Select]
Private spectrum As New Un4seen.Bass.Misc.Visuals
Public Sub SpectrumVisualizer(ByVal handle As Integer, ByVal visbox As PictureBox)
    visbox.Image = spectrum.CreateSpectrumLinePeak(handle, visbox.Width, visbox.Height, Color.Aqua, Color.DeepSkyBlue, Color.White, Color.Black, 4, 2, 1, 20, False, False, True)
End Sub

Example:
Code: [Select]
Public Class Form1
    Private itemsList As New ListBox
    Private time As New Timer
    Private openFileDLG As New OpenFileDialog
    Private conText1 As New ContextMenuStrip
    Private visBox As New PictureBox
    Private spectrum As New Un4seen.Bass.Misc.Visuals
    Private toolStrip1 As New ToolStripMenuItem("Load")
    Private toolStrip2 As New ToolStripMenuItem("Play")
    Private toolStrip3 As New ToolStripMenuItem("Stop")
    Private toolStrip4 As New ToolStripMenuItem("Clear")
    Private toolSeparate1 As New ToolStripSeparator
    Private toolStrip5 As New ToolStripMenuItem("VisualON")
    Private toolSeparate2 As New ToolStripSeparator
    Private toolStrip6 As New ToolStripMenuItem("Exit")
    Private tip As New ToolTip
    Private stream As Integer
    Public Sub New()
        MyBase.New()
        InitializeComponent()
        BASS_Init_Register()
        ControlProperties()
        Me.Controls.AddRange(New Control() {itemsList, visBox})
        Me.Size = New Size(300, 150)
        Me.Text = "SongsItemsList Sample (RightClick)"
        Me.MinimizeBox = False
        Me.MaximizeBox = False
        Me.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink
        Me.CenterToScreen()
        AddHandler itemsList.DoubleClick, AddressOf itemsList_DoubleClick
        AddHandler itemsList.MouseHover, AddressOf itemsList_MouseHover
        AddHandler toolStrip1.Click, AddressOf toolStrip1_Click
        AddHandler toolStrip2.Click, AddressOf toolStrip2_Click
        AddHandler toolStrip3.Click, AddressOf toolStrip3_Click
        AddHandler toolStrip4.Click, AddressOf toolStrip4_Click
        AddHandler toolStrip5.Click, AddressOf toolStrip5_Click
        AddHandler toolStrip6.Click, AddressOf toolStrip6_Click
        AddHandler time.Tick, AddressOf time_Tick
    End Sub
    Public Sub ControlProperties()
        With openFileDLG
            .FileName = Nothing
            .Filter = "Song file(*.mp3)|*.mp3"
        End With
        tip.AutomaticDelay = 10
        tip.AutoPopDelay = 3000
        tip.ShowAlways = True
        conText1.Items.AddRange(New ToolStripItem() {toolStrip1, toolStrip2, toolStrip3, toolStrip4, toolSeparate1, toolStrip5, toolSeparate2, toolStrip6})
        itemsList.Size = New Size(290, 125)
        itemsList.ScrollAlwaysVisible = True
        itemsList.ContextMenuStrip = conText1
        conText1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System
        conText1.Size = New System.Drawing.Size(120, 164)
        toolSeparate1.Size = New System.Drawing.Size(149, 6)
        toolSeparate2.Size = New System.Drawing.Size(149, 6)
        visBox.BackColor = Color.Black
        visBox.Dock = DockStyle.Fill
        visBox.ContextMenuStrip = conText1
        time.Interval = 40
    End Sub
    Public Sub BASS_AddSongsItemsList()
        If openFileDLG.ShowDialog = Windows.Forms.DialogResult.OK Then
            Un4seen.Bass.Bass.BASS_StreamFree(stream)
            Dim file As String = openFileDLG.FileName
            itemsList.Items.Add(file)
            itemsList.SelectedIndex += 1
            If itemsList.SelectedItem <> Nothing Then
                Dim itemsFile As String = itemsList.SelectedItem.ToString
                stream = Un4seen.Bass.Bass.BASS_StreamCreateFile(itemsFile, 0, 0, Un4seen.Bass.BASSFlag.BASS_DEFAULT)
            End If
        End If
    End Sub
    Public Sub BASS_Init_Register()
        Dim device As Integer = -1
        Dim freq As Integer = 44100
        Dim flags As Un4seen.Bass.BASSInit = Un4seen.Bass.BASSInit.BASS_DEVICE_DEFAULT
        Dim win As System.IntPtr = IntPtr.Zero
        Dim email As String = "xxx@gmail.com"
        Dim registrationKey As String = "2Xxxxxxxxxxxxxx"
        Un4seen.Bass.BassNet.Registration(email, registrationKey)
        Un4seen.Bass.Bass.BASS_Init(device, freq, flags, win)
    End Sub
    Public Sub itemsList_DoubleClick(ByVal sender As Object, ByVal e As EventArgs)
        If stream <> 0 Then
            Un4seen.Bass.Bass.BASS_StreamFree(stream)
            Un4seen.Bass.Bass.BASS_ChannelPlay(stream, True)
            If itemsList.SelectedItem <> Nothing Then
                Dim itemsFile As String = itemsList.SelectedItem.ToString
                stream = Un4seen.Bass.Bass.BASS_StreamCreateFile(itemsFile, 0, 0, Un4seen.Bass.BASSFlag.BASS_DEFAULT)
                If stream <> Nothing Then
                    Un4seen.Bass.Bass.BASS_ChannelPlay(stream, True)
                    time.Enabled = True
                End If
            End If
        End If
    End Sub
    Public Sub toolStrip1_Click(ByVal sender As Object, ByVal e As EventArgs)
        BASS_AddSongsItemsList()
    End Sub
    Public Sub toolStrip2_Click(ByVal sender As Object, ByVal e As EventArgs)
        BASS_SelectIndexItemsCount(stream, itemsList)
        Un4seen.Bass.Bass.BASS_ChannelPlay(stream, True)
        time.Enabled = True
    End Sub
    Public Sub toolStrip3_Click(ByVal sender As Object, ByVal e As EventArgs)
        Un4seen.Bass.Bass.BASS_ChannelStop(stream)
        If Un4seen.Bass.Bass.BASS_ChannelIsActive(stream) = Un4seen.Bass.BASSActive.BASS_ACTIVE_STOPPED Then
           tip.SetToolTip(itemsList, "Song Stop")
            Threading.Thread.Sleep(1000)
        End If
    End Sub
    Public Sub toolStrip4_Click(ByVal sender As Object, ByVal e As EventArgs)
        If itemsList.SelectedItem = Nothing Then Return
        itemsList.Items.RemoveAt(itemsList.SelectedIndex)
    End Sub
    Public Sub toolStrip5_Click(ByVal sender As Object, ByVal e As EventArgs)
        Select Case toolStrip5.Text
            Case "VisualON"
                itemsList.Hide()
                toolStrip5.Text = "VisualOFF"
            Case Else
                itemsList.Show()
                toolStrip5.Text = "VisualON"
        End Select
    End Sub
    Public Sub toolStrip6_Click(ByVal sender As Object, ByVal e As EventArgs)
        Me.Close()
    End Sub
    Public Sub itemsList_MouseHover(ByVal sender As Object, ByVal e As EventArgs)
        tip.SetToolTip(itemsList, "DoubleClick items to Playing")
    End Sub
    Public Function BASS_SelectIndexItemsCount(ByVal handle As Integer, ByVal itemsList As ListBox) As Integer
        Dim index As Integer = Nothing
        Dim itemsFile As String = Nothing
        If Not handle = Nothing Then Un4seen.Bass.Bass.BASS_StreamFree(handle)
        For x As Integer = 0 To itemsList.Items.Count - 1
            If itemsList.GetSelected(x) = True Then
                index &= x
                Exit For
            End If
        Next
        Try
            itemsList.SelectedIndex = index
            itemsFile = itemsList.SelectedItem.ToString
            stream = Un4seen.Bass.Bass.BASS_StreamCreateFile(itemsFile, 0, 0, Un4seen.Bass.BASSFlag.BASS_DEFAULT)
        Catch ex As Exception
            MsgBox("Pleased add song to the list")
        End Try
        Return handle
    End Function
    Public Sub BASS_percentMousePosition(ByVal tip As ToolTip, ByVal time As Timer)
        Dim pos As Integer = Un4seen.Bass.Bass.BASS_ChannelGetPosition(stream, Un4seen.Bass.BASSMode.BASS_POS_BYTES)
        Dim len As Integer = Un4seen.Bass.Bass.BASS_ChannelGetLength(stream, Un4seen.Bass.BASSMode.BASS_POS_BYTES)
        Dim percent As Integer = Math.Round((pos / len) * 100)
        tip.SetToolTip(itemsList, "Playing.." & percent & "/100")
        tip.SetToolTip(visBox, "Playing.." & percent & "/100")
    End Sub
    Public Sub time_Tick(ByVal sender As Object, ByVal e As EventArgs)
        BASS_percentMousePosition(tip, time)
        SpectrumVisualizer(stream, visBox)
        If Un4seen.Bass.Bass.BASS_ChannelIsActive(stream) = Un4seen.Bass.BASSActive.BASS_ACTIVE_STOPPED Then
            tip.SetToolTip(itemsList, "Song End")
            time.Enabled = False
        End If
    End Sub
    Public Sub SpectrumVisualizer(ByVal handle As Integer, ByVal visbox As PictureBox)
        visbox.Image = spectrum.CreateSpectrumLinePeak(handle, visbox.Width, visbox.Height, Color.Aqua, Color.DeepSkyBlue, Color.White, Color.Black, 4, 2, 1, 20, False, False, True)
    End Sub
End Class
« Last Edit: 5 Nov '12 - 08:46 by sak2005 »

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #61 on: 9 Nov '12 - 08:42 »
MiniBassUn4Seen Sample Project Click here

Get MiniSpectrumVisualizer ;D
Get SongNameSlideShow ;D
Get MiniLedLevelMeter ;D

« Last Edit: 9 Nov '12 - 08:46 by sak2005 »

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #62 on: 11 Nov '12 - 18:22 »
Get BassUn4Seen LED & VU Meter Click here

Get LED and VU analog.dll in the sample project.


sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #63 on: 12 Nov '12 - 10:15 »
Bonus: Full Sound Meter Click here

RightClick to PlayOnLoad and Replay when song end. ;D

« Last Edit: 12 Nov '12 - 10:25 by sak2005 »

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #64 on: 13 Nov '12 - 09:31 »
Get SongsList DragDrop ;D

DoubleClick ItemList to Playing.
RightClick to songStop or ExitApp.

Code: [Select]
Public Class Form1
    Private spectrum As New Un4seen.Bass.Misc.Visuals
    Private strm As Integer
    Public Sub New()
        MyBase.New()
        InitializeComponent()
        Me.CenterToScreen()
        Un4seen.Bass.Bass.BASS_Init(-1, 44100, Un4seen.Bass.BASSInit.BASS_DEVICE_DEFAULT, System.IntPtr.Zero)
        Timer1.Interval = 35
    End Sub
    Private Sub ListBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragDrop
        If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
            Dim Items() As Object = CType(e.Data.GetData(DataFormats.FileDrop), System.Object)
            Dim File As Object
            For Each File In Items
                If System.IO.File.Exists(File) Then
                    AddFile(File.ToString)
                ElseIf System.IO.Directory.Exists(File) Then
                    FindFiles(File.ToString)
                End If
            Next
        End If
    End Sub
    Private Sub ListBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragEnter
        PictureBox1.Hide()
        If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub
    Public Sub FindFiles(ByVal Directory As String)
        Try
            Dim Files As String() = System.IO.Directory.GetFiles(Directory, "*")
            Dim File As String
            For Each File In Files
                AddFile(File)
            Next
        Catch
        End Try
        Try
            Dim Dirs As String() = System.IO.Directory.GetDirectories(Directory, "*")
            Dim Dir As String
            For Each Dir In Dirs
                FindFiles(Dir)
            Next
        Catch
        End Try
    End Sub
    Public Sub AddFile(ByVal FilePath As String)
        ListBox1.Items.Add(FilePath)
    End Sub
    Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        ToolTip1.SetToolTip(ListBox1, Nothing)
        If Strings.InStr(ListBox1.SelectedItem, ".mp3") Then
            Un4seen.Bass.Bass.BASS_ChannelPlay(strm, True)
            PictureBox1.Show()
            Timer1.Enabled = True
        Else
            Process.Start(ListBox1.SelectedItem)
        End If
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim lev As Integer = Un4seen.Bass.Bass.BASS_ChannelGetLevel(strm)
        VuMeter1.Level = Un4seen.Bass.Utils.LowWord32(lev) * 1.9
        VuMeter2.Level = Un4seen.Bass.Utils.HighWord32(lev) * 1.9
        PictureBox1.Image = spectrum.CreateSpectrumLinePeak(strm, PictureBox1.Width, PictureBox1.Height, Color.Aqua, Color.DeepSkyBlue, Color.White, Color.Black, 4, 2, 1, 20, False, False, True)
        If Un4seen.Bass.Bass.BASS_ChannelIsActive(strm) = Un4seen.Bass.BASSActive.BASS_ACTIVE_STOPPED Then
            Un4seen.Bass.Bass.BASS_ChannelPlay(strm, False)
        End If
    End Sub
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        Un4seen.Bass.Bass.BASS_StreamFree(strm)
        If Strings.InStr(ListBox1.SelectedItem, ".mp3") Then
            Try
                ToolTip1.SetToolTip(ListBox1, "DoubleCilck to Playing")
            Catch
            End Try
            strm = Un4seen.Bass.Bass.BASS_StreamCreateFile(ListBox1.SelectedItem.ToString, 0, 0, Un4seen.Bass.BASSFlag.BASS_DEFAULT)
        Else
            Try
                ToolTip1.SetToolTip(ListBox1, "DoubleCilck to Open")
            Catch
            End Try
        End If
    End Sub
    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
        End Sub
    Private Sub StopToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopToolStripMenuItem.Click
        Un4seen.Bass.Bass.BASS_ChannelStop(strm)
        PictureBox1.Hide()
        Timer1.Enabled = False
    End Sub
    Private Sub PictureBox1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseHover
        ToolTip1.SetToolTip(PictureBox1, "Dragdrop dir or files here")
    End Sub
    Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave
        ToolTip1.SetToolTip(PictureBox1, Nothing)
    End Sub
End Class

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #65 on: 14 Nov '12 - 07:48 »
nBass1.8 Level Meter

RightClick to load and playing.

Code: [Select]
Public Class Form1
    Inherits Form
    Private fdlg As New OpenFileDialog
    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub
    Private strm As Integer
    Public Sub New()
        MyBase.New()
        InitializeComponent()
        nBass.InitStart()
        Timer1.Interval = 35
    End Sub
    Private Sub StopToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopToolStripMenuItem.Click
        nBass.LevelZero(VuMeter1, VuMeter2, VuMeter3, VuMeter4, Timer1)
        nBass.StreamStop(strm)
    End Sub
    Private Sub LoadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadToolStripMenuItem.Click
        If fdlg.ShowDialog = Windows.Forms.DialogResult.OK Then
            nBass.LevelZero(VuMeter1, VuMeter2, VuMeter3, VuMeter4, Timer1)
            nBass.StreamFree(strm)
            strm = nBass.StreamCreateFile(0, fdlg.FileName, 0, 0, 0)
        End If
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        nBass.StereoLevelMeter(strm, VuMeter1, VuMeter2)
        nBass.StereoLevelMeter(strm, VuMeter3, VuMeter4)
        If nBass.IsActive(strm) = nBass.ActiveState.Stopped Then
            nBass.LevelZero(VuMeter1, VuMeter2, VuMeter3, VuMeter4, Timer1)
        End If
    End Sub
    Private Sub PlayToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlayToolStripMenuItem.Click
        nBass.StreamPlay(strm, True, 0)
        Timer1.Enabled = True
    End Sub
    Private Sub PauseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PauseToolStripMenuItem.Click
        If nBass.IsActive(strm) = nBass.ActiveState.Playing Then
            nBass.StreamPause(strm)
            PauseToolStripMenuItem.Text = "Resume"
            nBass.LevelZero(VuMeter1, VuMeter2, VuMeter3, VuMeter4, Timer1)
        Else
            nBass.StreamResume(strm)
            PauseToolStripMenuItem.Text = "Pause"
            Timer1.Enabled = True
        End If
    End Sub
End Class
'--------------------------------------------------------------
Class nBass
    Inherits Object
    <System.Runtime.InteropServices.DllImport("basswma.dll", EntryPoint:="BASS_WMA_StreamCreateFile")> _
    Public Shared Function _LoadWMAStream _
    (ByVal mem As Integer, _
     ByVal filename As System.IntPtr, _
     ByVal offset As Integer, _
     ByVal length As Integer, _
     ByVal flags As Integer) As System.IntPtr
    End Function
    <System.Runtime.InteropServices.DllImport("bass.dll")> _
    Private Shared Function BASS_StreamCreateFile _
    (ByVal mem As Integer, _
     ByVal [file] As String, _
     ByVal offset As Integer, _
     ByVal Length As Integer, _
     ByVal flags As nBassFlag) As Integer
    End Function
    Public Shared Function StreamCreateFile _
    (ByVal mem As Integer, _
     ByVal [file] As String, _
     ByVal offset As Integer, _
     ByVal Length As Integer, _
     ByVal flags As nBassFlag) As Integer
        Return BASS_StreamCreateFile(mem, [file], offset, Length, nBassFlag.nBASS_DEFAULT)
    End Function
    <System.Runtime.InteropServices.DllImport("bass.dll")> _
    Private Shared Function BASS_StreamPlay _
    (ByVal handle As Integer, _
     ByVal flush As Boolean, _
     ByVal flags As nBassFlag) As Integer
    End Function
    Public Shared Function StreamPlay _
    (ByVal handle As System.IntPtr, _
     ByVal flush As Integer, _
     ByVal flags As nBassFlag)
        Return BASS_StreamPlay(handle, flush, nBassFlag.nBASS_DEFAULT)
    End Function
    <System.Runtime.InteropServices.DllImport("bass.dll")> _
    Private Shared Function BASS_ChannelPause(ByVal handle As Integer) As Integer
    End Function
    Public Shared Function StreamPause(ByVal handle As Integer) As Integer
        Return BASS_ChannelPause(handle)
    End Function
    <System.Runtime.InteropServices.DllImport("bass.dll")> _
    Private Shared Function BASS_ChannelResume(ByVal handle As Integer) As Integer
    End Function
    Public Shared Function StreamResume(ByVal handle As Integer) As Integer
        BASS_ChannelResume(handle)
    End Function
    <System.Runtime.InteropServices.DllImport("bass.dll")> _
    Private Shared Function BASS_ChannelStop(ByVal handle As Integer) As Integer
    End Function
    Public Shared Function StreamStop(ByVal handle As Integer) As Integer
        BASS_ChannelStop(handle)
    End Function
    <System.Runtime.InteropServices.DllImport("bass.dll")> _
    Private Shared Function BASS_StreamFree(ByVal handle As Integer) As Integer
    End Function
    Public Shared Function StreamFree(ByVal handle As Integer)
        Return BASS_StreamFree(handle)
    End Function
    Public Shared Function InitStart() As Integer
        BASS_Init(-1, 44100, nBassInit.nBASS_DEVICE_DEFAULT, System.IntPtr.Zero)
        BASS_Start()
    End Function
    <System.Runtime.InteropServices.DllImport("bass.dll", EntryPoint:="BASS_GetVersion")> _
    Public Shared Function _GetVersion() As Integer
    End Function
    <System.Runtime.InteropServices.DllImport("bass.dll", EntryPoint:="BASS_GetDeviceDescription")> _
    Public Shared Function _GetDeviceDescription(ByVal devnum As Integer) As System.IntPtr
    End Function
    <System.Runtime.InteropServices.DllImport("bass.dll")> _
    Private Shared Function BASS_Init _
    (ByVal device As Integer, _
     ByVal freq As Integer, _
     ByVal flags As nBassInit, _
     ByVal win As System.IntPtr) As Integer
    End Function
    Private Shared Function Init _
    (ByVal device As Integer, _
     ByVal freq As Integer, _
     ByVal flags As nBassInit, _
     ByVal win As System.IntPtr) As Integer
        Return BASS_Init(device, freq, flags, win)
    End Function
    <System.Runtime.InteropServices.DllImport("bass.dll", EntryPoint:="BASS_Stop")> _
   Public Shared Function _Stop() As Integer
    End Function
    <System.Runtime.InteropServices.DllImport("bass.dll", EntryPoint:="BASS_Pause")> _
    Public Shared Function _Pause() As Integer
    End Function
    <System.Runtime.InteropServices.DllImport("bass.dll", EntryPoint:="BASS_Free")> _
    Public Shared Sub _Free()
    End Sub
    <System.Runtime.InteropServices.DllImport("bass.dll", EntryPoint:="BASS_GetCPU")> _
    Public Shared Function _GetCPU() As Single
    End Function
    <System.Runtime.InteropServices.DllImport("bass.dll")> _
    Private Shared Function BASS_Start() As Integer
    End Function
    Private Shared Function Start()
        Return BASS_Start()
    End Function
    <System.Runtime.InteropServices.DllImport("bass.dll")> _
    Private Shared Function BASS_ChannelGetLevel(ByVal handle As Integer) As Integer
    End Function
    <System.Runtime.InteropServices.DllImport("bass.dll")> _
    Private Shared Function BASS_ChannelIsActive(ByVal handle As Integer) As Integer
    End Function
    Public Shared Function IsActive(ByVal handle As Integer) As ActiveState
        Return BASS_ChannelIsActive(handle)
    End Function
    Private Shared Function HiWord(ByVal Number As Integer) As Integer
        Return (Number >> 16) And 65535
    End Function
    Private Shared Function LoWord(ByVal Number As Integer) As Integer
        Return Number And 65535
    End Function
    Public Shared Function StereoLevelMeter _
    (ByVal handle As Integer, _
     ByVal levL As VU_MeterLibrary.VuMeter, _
     ByVal levR As VU_MeterLibrary.VuMeter) As Integer
        Dim lev As Integer = BASS_ChannelGetLevel(handle)
        levL.Level = LoWord(lev) * 465
        levR.Level = HiWord(lev) * 465
    End Function
    Public Shared Function LevelZero _
    (ByVal vu1L As VU_MeterLibrary.VuMeter, _
     ByVal vu2R As VU_MeterLibrary.VuMeter, _
     ByVal led3L As VU_MeterLibrary.VuMeter, _
     ByVal led4R As VU_MeterLibrary.VuMeter, _
     ByVal timeStop As Timer) As Integer
        vu1L.Level = 0
        vu2R.Level = 0
        led3L.Level = 0
        led4R.Level = 0
        timeStop.Enabled = False
    End Function
    <Flags()> _
    Public Enum nBassInit
#Region "nBassInit Fields"
        nBASS_DEVICE_DEFAULT = 0
        nBASS_DEVICE_8BITS = 1
        nBASS_DEVICE_MONO = 2
        nBASS_DEVICE_3D = 4
        nBASS_DEVICE_LATENCY = 256
        nBASS_DEVICE_CPSPEAKERS = 1024
        nBASS_DEVICE_SPEAKERS = 2048
        nBASS_DEVICE_NOSPEAKER = 4096
        nBASS_DEVIDE_DMIX = 8192
#End Region
    End Enum
    <Flags()> _
   Public Enum nBassFlag
#Region "nBassFlag Fields"
        nBASS_DEFAULT = 0
        nBASS_SAMPLE_FLOAT = 256
        nBASS_STREAM_PRESCAN = 131072
        nBASS_STREAM_AUTOFREE = 262144
        nBASS_STREAM_STATUS = 8388608
        nBASS_UNICODE = -2147483648
#End Region
    End Enum
    Public Enum ActiveState
#Region "ActiveState Fields"
        Stopped = 0
        Playing = 1
        Stalled = 2
        Paused = 3
#End Region
    End Enum
    <Flags()> _
   Public Enum nBassMode
#Region "nBassMode Fields"
        nBASS_POS_BYTES = 0
        nBASS_POS_MUSIC_ORDERS = 1
        nBASS_POS_MIDI_TICK = 2
        nBASS_MUSIC_POSRESET = 32768
        nBASS_MUSIC_POSRESETEX = 4194304
        nBASS_MIXER_NORAMPIN = 8388608
        nBASS_POS_DECODE = 268435456
        nBASS_POS_DECODETO = 536870912
        nBASS_MIDI_DECAYSEEK = 16384
#End Region
    End Enum
End Class

« Last Edit: 14 Nov '12 - 09:11 by sak2005 »

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #66 on: 25 Nov '12 - 08:52 »
Grid LED Spectrum Visualizer ;D

Download: PeakMeterCtrl.dll Click here

Using DLL: When download complete.
               DragAndDrop add dll file to the Toolbox Components.
               DragAndDrop add dll file to the form application.

Example: Try to run with Loop set data LED Spectrum Visualizer.
             Not must Create Object components.
             Copie all code and paste to the form application.

Code: [Select]
Public Class Form1
    Private Button1 As New Button
    Private CheckBox1 As New CheckBox
    Private CheckBox2 As New CheckBox
    Private CheckBox3 As New CheckBox
    Private Label1 As New Label
    Private Label2 As New Label
    Private Label3 As New Label
    Private Label4 As New Label
    Private Label5 As New Label
    Private Label6 As New Label
    Private Timer1 As New Timer
    Public Sub New()
        MyBase.New()
        InitializeComponent()
        FormProperties()
        ControlProperties()
        Timer1.Enabled = True
        AddHandler Button1.Click, AddressOf Button1_Click
        AddHandler CheckBox1.CheckedChanged, AddressOf CheckBox1_CheckedChanged
        AddHandler CheckBox2.CheckedChanged, AddressOf CheckBox2_CheckedChanged
        AddHandler CheckBox3.CheckedChanged, AddressOf CheckBox3_CheckedChanged
        AddHandler Label1.Click, AddressOf Label1_Click
        AddHandler Label2.Click, AddressOf Label2_Click
        AddHandler Label3.Click, AddressOf Label3_Click
        AddHandler Label4.Click, AddressOf Label4_Click
        AddHandler Label5.Click, AddressOf Label5_Click
        AddHandler Label6.Click, AddressOf Label6_Click
        AddHandler Timer1.Tick, AddressOf Timer1_Tick
    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
        Dim rand As New System.Random
        Dim arr As Integer() = New Integer(15 - 1) {}
        Dim iCount As Integer = 0
        Do While iCount < arr.Length
            arr(iCount) = rand.[Next](0, 100)
            iCount += 1
            Timer1.Interval = rand.[Next](450, 550)
        Loop
        Me.PeakMeterCtrl1.SetData(arr, 0, arr.Length)
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Select Case Button1.Text
            Case "Start"
                Timer1.Enabled = True
                Button1.Text = "Stop"
            Case Else
                Timer1.Enabled = False
                Button1.Text = "Start"
        End Select
    End Sub
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Select Case CheckBox1.CheckState
            Case CheckState.Checked
                PeakMeterCtrl1.FalloffEffect = True
            Case Else
                PeakMeterCtrl1.FalloffEffect = False
        End Select
        If (PeakMeterCtrl1.BackColor = System.Drawing.SystemColors.Control) Then PeakMeterCtrl1.FalloffColor = Color.Black
    End Sub
    Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Select Case CheckBox2.CheckState
            Case CheckState.Checked
                PeakMeterCtrl1.ShowGrid = True
                PeakMeterCtrl1.BackColor = System.Drawing.SystemColors.Control
                CheckBox3.Enabled = True
            Case Else
                PeakMeterCtrl1.ShowGrid = False
                CheckBox3.Enabled = False
        End Select
        If CheckBox1.CheckState = CheckState.Checked Then
            PeakMeterCtrl1.FalloffColor = Color.Black
        End If
    End Sub
    Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Select Case CheckBox3.CheckState
            Case CheckState.Checked
                PeakMeterCtrl1.ColoredGrid = True
            Case Else
                PeakMeterCtrl1.ColoredGrid = False
        End Select
    End Sub
    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            PeakMeterCtrl1.BackColor = ColorDialog1.Color
        End If
        Select Case PeakMeterCtrl1.BackColor
            Case Color.Black
                PeakMeterCtrl1.FalloffColor = Color.White
            Case Color.White
                PeakMeterCtrl1.FalloffColor = Color.Black
            Case Else
                PeakMeterCtrl1.FalloffColor = Color.Red
        End Select
        If (PeakMeterCtrl1.BackColor = Color.Red) Then
            PeakMeterCtrl1.FalloffColor = Color.White
        End If
    End Sub
    Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            PeakMeterCtrl1.FalloffColor = ColorDialog1.Color
        End If
    End Sub
    Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Not (PeakMeterCtrl1.BackColor = Color.Black) Then PeakMeterCtrl1.BackColor = Color.Black
        PeakMeterCtrl1.ColorNormal = Color.Green
        PeakMeterCtrl1.ColorMedium = Color.Yellow
        PeakMeterCtrl1.ColorHigh = Color.Red
        If CheckBox1.CheckState = CheckState.Checked Then
            PeakMeterCtrl1.FalloffEffect = True
            PeakMeterCtrl1.FalloffColor = Color.White
            PeakMeterCtrl1.Start(50)
        End If
        CheckBox1.Checked = False
        CheckBox2.Checked = False
        CheckBox3.Checked = False
        CheckBox3.Enabled = False
    End Sub
    Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            PeakMeterCtrl1.ColorNormal = ColorDialog1.Color
        End If
    End Sub
    Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            PeakMeterCtrl1.ColorMedium = ColorDialog1.Color
        End If
    End Sub
    Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            PeakMeterCtrl1.ColorHigh = ColorDialog1.Color
        End If
    End Sub
    Private Sub FormProperties()
        Me.CenterToScreen()
        Me.Text = "Grid LED Spectrum"
        Me.MaximizeBox = False
        Me.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink
        Me.Controls.AddRange(New Control() {Button1, CheckBox1, CheckBox2, CheckBox3, Label1, Label2, Label3, Label4, Label5, Label6})
    End Sub
    Private Sub ControlProperties()
        Button1.Text = "Stop"
        Button1.Location = New Point(111, 231)
        Button1.Cursor = Cursors.Hand
        CheckBox1.Text = "Show FallOff Effect"
        CheckBox1.Location = New Point(12, 144)
        CheckBox1.AutoSize = True
        CheckBox1.Checked = False
        CheckBox2.Text = "Show Grid"
        CheckBox2.Location = New Point(130, 144)
        CheckBox2.AutoSize = True
        CheckBox2.Checked = False
        CheckBox3.Text = "Colored Grid"
        CheckBox3.Location = New Point(205, 144)
        CheckBox3.AutoSize = True
        CheckBox3.Checked = False
        CheckBox3.Enabled = False
        Label1.AutoSize = True
        Label1.Text = "Background Color"
        Label1.Cursor = Cursors.Hand
        Label1.Location = New Point(111, 173)
        Label1.BorderStyle = BorderStyle.FixedSingle
        Label2.AutoSize = True
        Label2.Text = "FallOff Color"
        Label2.Cursor = Cursors.Hand
        Label2.Location = New Point(12, 173)
        Label2.BorderStyle = BorderStyle.FixedSingle
        Label3.AutoSize = True
        Label3.Text = "Default"
        Label3.Cursor = Cursors.Hand
        Label3.Location = New Point(240, 173)
        Label3.BorderStyle = BorderStyle.FixedSingle
        Label4.AutoSize = True
        Label4.Text = "Normal Color"
        Label4.Cursor = Cursors.Hand
        Label4.Location = New Point(12, 202)
        Label4.BorderStyle = BorderStyle.FixedSingle
        Label5.AutoSize = True
        Label5.Text = "Medium Color"
        Label5.Cursor = Cursors.Hand
        Label5.Location = New Point(115, 202)
        Label5.BorderStyle = BorderStyle.FixedSingle
        Label6.AutoSize = True
        Label6.Text = "High Color"
        Label6.Cursor = Cursors.Hand
        Label6.Location = New Point(224, 202)
        Label6.BorderStyle = BorderStyle.FixedSingle
        PeakMeterCtrl1.ShowGrid = False
        PeakMeterCtrl1.FalloffEffect = False
        PeakMeterCtrl1.ColoredGrid = False
        PeakMeterCtrl1.BackColor = Color.Black
        PeakMeterCtrl1.FalloffColor = Color.White
        PeakMeterCtrl1.Start(50)
    End Sub
End Class

« Last Edit: 26 Nov '12 - 03:06 by sak2005 »

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #67 on: 4 Dec '12 - 18:06 »
Sample code nBass 1.8
Creatting nBass Player Functions

nBass Class:
Code: [Select]
Public Class nBass
    Private Declare Function BASS_Init Lib "bass.dll" (ByVal device As Integer, ByVal freq As Integer, ByVal flags As Integer, ByVal win As System.IntPtr) As Integer
    Private Declare Function BASS_Start Lib "bass.dll" () As Integer
    Private Declare Function BASS_GetVersion Lib "bass.dll" () As Integer
    Private Declare Function BASS_GetDeviceDescription Lib "bass.dll" (ByVal devnum As Integer) As Integer
    Private Declare Function BASS_StreamCreateFile Lib "bass.dll" (ByVal mem As Integer, ByVal fileName As String, ByVal offset As Integer, ByVal Length As Integer, ByVal flags As Integer) As Integer
    Private Declare Function BASS_StreamFree Lib "bass.dll" (ByVal handle As Integer) As Integer
    Private Declare Function BASS_StreamPlay Lib "bass.dll" (ByVal handle As Integer, ByVal flush As Boolean, ByVal flags As Integer) As Integer
    Private Declare Function BASS_ChannelStop Lib "bass.dll" (ByVal handle As Integer) As Integer
    Public Declare Function BASS_ChannelIsActive Lib "bass.dll" (ByVal handle As Integer) As Integer 'connect form used 'Public'

    Shared Sub New()
        InitStart()
    End Sub

    Public Shared Function InitStart() As Integer
        BASS_Init(-1, 44100, 0, System.IntPtr.Zero)
        BASS_Start()
    End Function

    Public Shared Function BASS_LoadStreamFile(ByVal handle As Integer, ByVal fileName As String) As String
        BASS_StreamFree(handle)
        Return BASS_StreamCreateFile(0, fileName, 0, 0, 0)  'return type 'String'
    End Function

    Public Shared Function BASS_StreamPlay(ByVal handle As Integer, ByVal flush As Boolean) As Integer
        BASS_StreamPlay(handle, flush, 0)
    End Function

    Public Shared Function BASS_StreamStop(ByVal handle As Integer) As Integer
        BASS_ChannelStop(handle)
    End Function

    Public Shared Function BASS_GetStringVersion() As String
        BASS_GetStringVersion = Trim(Str(GetLoWord(BASS_GetVersion))) & "." & Trim(Str(GetHiWord(BASS_GetVersion)))
    End Function

    Private Shared Function GetHiWord(ByRef lparam As Integer) As Integer
        GetHiWord = lparam \ &H10000 And &HFFFF
    End Function

    Private Shared Function GetLoWord(ByRef lparam As Integer) As Integer
        GetLoWord = lparam And &HFFFF
    End Function

    Public Enum IsActive As Integer  'state flag BASS_ChannelIsActive.
        Play = 1
        [Stop] = 0
    End Enum
End Class

Example:
Code: [Select]
Public Class Form1
    Private openDLG As OpenFileDialog
    Private timer1 As Timer
    Private Shared strm As Integer 'conect nBass class used 'Shared'

    Public Sub New()
        MyBase.New()
        InitializeComponent()
        Me.TopMost = True
        BassDllChecked()
        btnLoad.Text = "Load"
        btnPlay.Text = "Play"
        btnStop.Text = "Stop"
        Label1.Text = "Active: -  -  -  -"
        openDLG = New OpenFileDialog
        timer1 = New Timer
        openDLG.FileName = Nothing
        openDLG.Filter = "Song file(*.mp3;*.wav)|*.mp3;*.wav"
        AddHandler timer1.Tick, AddressOf timer1_Tick
    End Sub

    Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
        If openDLG.ShowDialog = Windows.Forms.DialogResult.OK Then
            strm = nBass.BASS_LoadStreamFile(strm, openDLG.FileName)
            timer1.Enabled = True
        End If
    End Sub

    Private Shared Sub btnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click
        nBass.BASS_StreamPlay(strm, True)
    End Sub

    Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
        nBass.BASS_StreamStop(strm)
    End Sub

    Private Sub timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
        Select Case nBass.BASS_ChannelIsActive(strm)
            Case nBass.IsActive.Play
                Label1.Text = "Active: Playing.."
            Case Else
                Label1.Text = "Active: Stopped"
        End Select
    End Sub

    Private Sub BassDllChecked()
        If Not My.Computer.FileSystem.FileExists(String.Concat(My.Computer.FileSystem.CurrentDirectory, "\", "bass.dll")) Then
            MsgBox("Not found bass.dll file in the debug folder.")
            Me.Close()
        ElseIf Not nBass.BASS_GetStringVersion() = "1.8" Then
            MsgBox("It's not bass.dll version 1.8")
            Me.Close()
        Else
            MsgBox(String.Concat("bass.dll version ", nBass.BASS_GetStringVersion()), 64, "")
        End If
    End Sub
End Class
« Last Edit: 4 Dec '12 - 19:13 by sak2005 »

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #68 on: 6 Dec '12 - 13:38 »
Get code other nbass Functions ;D

Start position: Balance song position with trackbar value.
Code: [Select]
Public Shared Function MaxPosition(ByVal trackPos As TrackBar, ByVal handle As Integer) As Long
        trackPos.Maximum = nBass.ChannelBytes2Seconds(handle, nBass.StreamGetLength(handle))
    End Function
-------------------------------------------------------------
End position: trackbar value = 0 If song end.
Code: [Select]
Public Shared Function MinPosition(ByVal handle As Integer, ByVal trackPos As TrackBar) As Integer
        If nBass.ChannelIsActive(handle) = ActiveState.Stopped Then
            trackPos.Value = nBass.ChannelSetPosition(handle, trackPos.Minimum)
        End If
-------------------------------------------------------------
Set position: Trackbar value current progress song position.
Code: [Select]
Public Shared Function ProgressPosition(ByVal trackPos As TrackBar, ByVal handle As Integer) As Long
        trackPos.Value = nBass.ChannelBytes2Seconds(handle, nBass.ChannelGetPosition(handle))
    End Function
--------------------------------------------------------------
Position scroll: Trackbar scrolling with mouse. Change song position.
Code: [Select]
Public Shared Function ScrollPosition(ByVal handle As Integer, ByVal trackPos As TrackBar) As Long
        nBass.ChannelSetPosition(handle, nBass.ChannelSeconds2Bytes(handle, trackPos.Value))
    End Function
« Last Edit: 8 Dec '12 - 16:54 by sak2005 »

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #69 on: 8 Dec '12 - 09:38 »
:Example:

nBass Class:
Code: [Select]
Public Class nBass
    Private Declare Function BassInit Lib "bass.dll" Alias "BASS_Init" (ByVal device As Integer, ByVal freq As Integer, ByVal flags As InitFlags, ByVal win As System.IntPtr) As Integer
    Private Declare Function BassStart Lib "bass.dll" Alias "BASS_Start" () As Integer
    Private Declare Function BassStreamFree Lib "bass.dll" Alias "BASS_StreamFree" (ByVal handle As Integer) As Integer
    Private Declare Function BassStreamCreateFile Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal mem As Integer, ByVal [file] As String, ByVal offset As Integer, ByVal Length As Integer, ByVal flags As StreamFlags) As Integer
    Private Declare Function BassStreamPlay Lib "bass.dll" Alias "BASS_StreamPlay" (ByVal handle As Integer, ByVal flush As Integer, ByVal flags As StreamPlayFlags) As Integer
    Private Declare Function BassChannelStop Lib "bass.dll" Alias "BASS_ChannelStop" (ByVal handle As Integer) As Integer
    Private Declare Function BassChannelPause Lib "bass.dll" Alias "BASS_ChannelPause" (ByVal handle As Integer) As Integer
    Private Declare Function BassChannelResume Lib "bass.dll" Alias "BASS_ChannelResume" (ByVal handle As Integer) As Integer
    Private Declare Function BassChannelIsActive Lib "bass.dll" Alias "BASS_ChannelIsActive" (ByVal handle As Integer) As ActiveState
    Private Declare Function BassStreamGetLength Lib "bass.dll" Alias "BASS_StreamGetLength" (ByVal handle As Integer) As Long
    Private Declare Function BassChannelGetPosition Lib "bass.dll" Alias "BASS_ChannelGetPosition" (ByVal handle As Integer) As Long
    Private Declare Function BassChannelBytes2Seconds Lib "bass.dll" Alias "BASS_ChannelBytes2Seconds" (ByVal handle As Integer, ByVal pos As Long) As Single
    Private Declare Function BassChannelSeconds2Bytes Lib "bass.dll" Alias "BASS_ChannelSeconds2Bytes" (ByVal handle As Integer, ByVal pos As Single) As Long
    Private Declare Function BassChannelSetPosition Lib "bass.dll" Alias "BASS_ChannelSetPosition" (ByVal handle As Integer, ByVal pos As Long) As Integer

    Private Shared Function BASS_Init(ByVal device As Integer, ByVal freq As Integer, ByVal flags As InitFlags, ByVal win As System.IntPtr) As Integer
        Return BassInit(device, freq, flags, win)
    End Function

    Private Shared Function BASS_Start() As Integer
        Return BassStart()
    End Function

    Private Shared Function BASS_StreamGetLength(ByVal handle As Integer) As Long
        Return BassStreamGetLength(handle)
    End Function

    Private Shared Function BASS_ChannelGetPosition(ByVal handle As Integer) As Long
        Return BassChannelGetPosition(handle)
    End Function

    Private Shared Function BASS_ChannelBytes2Seconds(ByVal handle As Integer, ByVal pos As Long) As Single
        Return BassChannelBytes2Seconds(handle, pos)
    End Function

    Private Shared Function BASS_ChannelSeconds2Bytes(ByVal handle As Integer, ByVal pos As Single) As Long
        Return BassChannelSeconds2Bytes(handle, pos)
    End Function

    Private Shared Function BASS_ChannelSetPosition(ByVal handle As Integer, ByVal pos As Long) As Integer
        Return BassChannelSetPosition(handle, pos)
    End Function

    Public Shared Function BASS_InitStart() As Integer
        BassInit(-1, 44100, InitFlags.BASS_DEVICE_DEFAULT, System.IntPtr.Zero)
        Return BassStart()
    End Function

    Public Shared Function BASS_StreamFree(ByVal handle As Integer) As Integer
        Return BassStreamFree(handle)
    End Function
    Public Shared Function BASS_StreamCreateFile(ByVal mem As Integer, ByVal [file] As String, ByVal offset As Integer, ByVal Length As Integer, ByVal flags As StreamFlags) As Integer
        Return BassStreamCreateFile(mem, [file], offset, Length, flags)
    End Function

    Public Shared Function BASS_StreamPlay(ByVal handle As Integer, ByVal flush As Integer, ByVal flags As Integer) As Integer
        Return BassStreamPlay(handle, flush, flags)
    End Function
    Public Shared Function BASS_ChannelStop(ByVal handle As Integer) As Integer
        BassChannelStop(handle)
    End Function

    Public Shared Function BASS_ChannelPause(ByVal handle As Integer) As Integer
        Return BassChannelPause(handle)
    End Function

    Public Shared Function BASS_ChannelResume(ByVal handle As Integer) As Integer
        BassChannelResume(handle)
    End Function

    Public Shared Function BASS_ChannelIsActive(ByVal handle As Integer) As ActiveState
        Return BassChannelIsActive(handle)
    End Function

    Public Shared Function BASS_MinPosition(ByVal handle As Integer) As Integer
        nBass.BASS_ChannelSetPosition(handle, 0)
        Return nBass.BASS_ChannelGetPosition(handle)
    End Function

    Public Shared Function BASS_MaxPosition(ByVal TrackBarName As TrackBar, ByVal handle As Integer) As Long
        TrackBarName.Maximum = nBass.BASS_ChannelBytes2Seconds(handle, nBass.BASS_StreamGetLength(handle))
        TrackBarName.TickFrequency = 30
    End Function

    Public Shared Function BASS_ScrollPosition(ByVal handle As Integer, ByVal TrackBarName As TrackBar) As Long
        nBass.BASS_ChannelSetPosition(handle, nBass.BASS_ChannelSeconds2Bytes(handle, TrackBarName.Value))
    End Function

    Public Shared Function BASS_CurrentPosition(ByVal handle As Integer) As Long
        Return nBass.BASS_ChannelBytes2Seconds(handle, nBass.BASS_ChannelGetPosition(handle))
    End Function

    Public Shared Function BASS_TotalTimeDuration(ByVal handle As Integer, ByVal Lbl As Label) As Integer
        Dim span As TimeSpan
        span = TimeSpan.FromSeconds(nBass.BASS_ChannelBytes2Seconds(handle, nBass.BASS_StreamGetLength(handle)))
        Lbl.Text = Strings.Left(span.ToString, 8)
    End Function

    Public Shared Function BASS_CurrentTimeDuration(ByVal handle As Integer) As String
        Dim span As System.TimeSpan
        span = TimeSpan.FromSeconds(nBass.BASS_ChannelBytes2Seconds(handle, nBass.BASS_ChannelGetPosition(handle)))
        If nBass.BASS_ChannelIsActive(handle) = ActiveState.Stopped Then
            span = TimeSpan.FromSeconds(0)
            Return span.ToString()
        Else
            Return Strings.Left(span.ToString, 8)
        End If
    End Function

    Public Shared Function BASS_PercentPosition(ByVal handle) As Integer
        Return (nBass.BASS_ChannelGetPosition(handle) / nBass.BASS_StreamGetLength(handle)) * 100
    End Function

    <Flags()> _
    Public Enum InitFlags
        BASS_DEVICE_DEFAULT = 0
        BASS_DEVICE_8BITS = 1
        BASS_DEVICE_MONO = 2
        BASS_DEVICE_LATENCY = 256
        BASS_DEVICE_CPSPEAKERS = 1024
        BASS_DEVICE_SPEAKERS = 2048
        BASS_DEVICE_NOSPEAKER = 4096
    End Enum

    <Flags()> _
    Public Enum StreamFlags
        [Default] = 0
        EightBits = 1
        Mono = 2
        ThreeDee = 4
        FX = 128
        Meta = 4194304
        SetPosition = 131072
        AutoFree = 262144
        DecodeOnly = 2097152
        FloatingPointChannels = 256
        FrontSpeakers = 16777216
        RearSpeakers = 33554432
        CentreSpeakers = 318767104
        LeftSpeakerModifier = 268435456
        RightSpeakerModifier = 536870912
    End Enum

    Public Enum StreamPlayFlags
        [Default] = 0
        [Loop] = 4
    End Enum

    Public Enum ActiveState
        Stopped = 0
        Playing = 1
        Stalled = 2
        Paused = 3
    End Enum
End Class

nBass Form:
Code: [Select]
Public Class Form1
    Private file As String
    Private strm As Integer

    Public Sub New()
        MyBase.New()
        Me.CenterToScreen()
        InitializeComponent()
        nBass.BASS_InitStart()
        ControlProperties()
        Label2.Text = "00:00:00"
        Label3.Text = "00:00:00"
        Label4.Text = "0%"
    End Sub

    Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
        BtnPauseResumeSwitch()
        Dim openfile As New OpenFileDialog
        openfile.FileName = Nothing
        openfile.Filter = "Song file(*.mp3;*.wav)|*.mp3;*.wav"
        If openfile.ShowDialog = Windows.Forms.DialogResult.OK Then
            file = openfile.FileName
            nBass.Bass_StreamFree(strm)
            strm = nBass.BASS_StreamCreateFile(0, file, 0, 0, nBass.StreamFlags.Default)
            nBass.BASS_TotalTimeDuration(strm, Label2)
            nBass.BASS_MaxPosition(TrackBar1, strm)
            Timer1.Enabled = True
        End If
    End Sub

    Private Sub btnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click
        BtnPauseResumeSwitch()
        If strm Then
            nBass.BASS_StreamPlay(strm, 1, nBass.StreamPlayFlags.Default)
            Timer2.Enabled = True
        End If
    End Sub

    Private Sub btnPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPause.Click
        If Not nBass.BASS_ChannelIsActive(strm) = nBass.ActiveState.Stopped Then
            Select Case btnPause.Text
                Case "Pause"
                    nBass.BASS_ChannelPause(strm)
                    btnPause.Text = "Resume"
                Case Else
                    nBass.BASS_ChannelResume(strm)
                    btnPause.Text = "Pause"
            End Select
        End If
    End Sub

    Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
        BtnPauseResumeSwitch()
        nBass.BASS_ChannelStop(strm)
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        StartActiveState()
    End Sub

    Private Sub BtnPauseResumeSwitch()
        If Strings.InStr(btnPause.Text, "Resume") Then
            btnPause.Text = "Pause"
        End If
    End Sub

    Private Sub StartActiveState()
        Select Case nBass.BASS_ChannelIsActive(strm)
            Case nBass.ActiveState.Stopped
                Label1.Text = "Stopped"
            Case nBass.ActiveState.Playing
                Label1.Text = "Playing.."
            Case nBass.ActiveState.Paused
                Label1.Text = "Paused"
            Case Else
                Label1.Text = "Stalled"
        End Select
    End Sub

    Private Sub EndActiveState()
        If nBass.BASS_ChannelIsActive(strm) = nBass.ActiveState.Stopped Then
            TrackBar1.Value = TrackBar1.Minimum
            Label4.Text = "0%"
            Timer2.Enabled = False
        End If
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Try
            TrackBar1.Value = nBass.BASS_CurrentPosition(strm)
        Catch ex As Exception
        End Try
        Label3.Text = nBass.BASS_CurrentTimeDuration(strm)
        Label4.Text = String.Concat(nBass.BASS_PercentPosition(strm), "%")
        EndActiveState()
    End Sub

    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        nBass.BASS_ScrollPosition(strm, TrackBar1)
    End Sub

    Private Sub ControlProperties()
        btnLoad.Cursor = Cursors.Hand
        btnPlay.Cursor = Cursors.Hand
        btnPause.Cursor = Cursors.Hand
        btnStop.Cursor = Cursors.Hand
    End Sub
End Class
« Last Edit: 8 Dec '12 - 16:55 by sak2005 »

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #70 on: 9 Dec '12 - 16:55 »
Get code nBass v1.8 : BassGetDeviceDescription ;D

Example:
Code: [Select]
Public Class Form1
    Private Declare Function BassGetDeviceDescription Lib "bass.dll" Alias "BASS_GetDeviceDescription" (ByVal devnum As Integer) As System.IntPtr
    Private cbBox As ComboBox
    
    Public Sub New()
        MyBase.New()
        Me.CenterToScreen()
        InitializeComponent()
        Me.Text = "nBass Device Info Sample"
        cbBox = New ComboBox
        cbBox.Text = "DeviceDiscription"
        cbBox.SetBounds(50, 100, 200, 15)
        Me.Controls.Add(cbBox)
    End Sub

    Private Sub BASS_GetDeviceNames(ByVal cbBox As ComboBox)
        Dim devnum As Integer
        For devnum = 0 To 1
            cbBox.Items.Add(BASS_GetDeviceDescription(devnum))
        Next devnum
        cbBox.Text = "DeviceDescription"
        Return
    End Sub

    Private Function BASS_GetDeviceDescription(ByVal devnum As Integer) As String
        Dim v_intPtr As System.IntPtr = BassGetDeviceDescription(devnum)
        Dim v_strDev As String = Nothing
        If Not (v_intPtr = System.IntPtr.Zero) Then
            v_strDev = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(v_intPtr)
        End If
        Return v_strDev
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            BASS_GetDeviceNames(cbBox)
        Catch ex As Exception
            MsgBox(ex.Message & vbCrLf & "You must add bass.dll into the debug folder.", 48, "Error!")
            Me.Dispose()
        End Try
    End Sub
End Class
« Last Edit: 9 Dec '12 - 17:11 by sak2005 »

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #71 on: 14 Dec '12 - 10:31 »
Get code: Creatting Spectrum Visualizer.

Visuals Class:
Code: [Select]
Public Class Visuals
    Inherits Object
    Private Declare Function BASS_ChannelGetData Lib "bass.dll" (ByVal handle As Integer, ByVal buffer As Single(), ByVal length As Integer) As Integer
    Private Shared a As Single()
    Private Shared b As Single()
    Private Shared c As Boolean
    Private Shared d As Integer
    Private Shared e As Integer
    Private Shared f As Integer
    Private Shared g As Integer
    Private Shared h As BASSData
    Private Shared i As Integer
    Private Shared j As Double
    Private Shared k As Boolean
    Public Sub New()
        MyBase.New()
        Visuals.a = New Single(2047) {}
        Visuals.b = New Single(2047) {}
        Visuals.c = Nothing
        Visuals.d = 9
        Visuals.e = 4
        Visuals.f = 4096
        Visuals.g = 2047
        Visuals.h = BASSData.BASS_DATA_FFT4096
        Visuals.i = 2047
        Visuals.j = 1
    End Sub
    Public Shared Function CreateSpectrumLinePeak(ByVal channel As Integer, ByVal width As Integer, ByVal height As Integer, ByVal color1 As System.Drawing.Color, ByVal color2 As System.Drawing.Color, ByVal color3 As System.Drawing.Color, ByVal background As System.Drawing.Color, ByVal linewidth As Integer, ByVal peakwidth As Integer, ByVal distance As Integer, ByVal peakdelay As Integer, ByVal linear As Boolean, ByVal fullSpectrum As Boolean, ByVal highQuality As Boolean) As System.Drawing.Bitmap
        Dim v_bitmap As System.Drawing.Bitmap
        Dim v_graphics As System.Drawing.Graphics
        Dim v_pen As System.Drawing.Pen
        Dim v_pen1 As System.Drawing.Pen
        Dim v_brush As System.Drawing.Brush
        If (((((channel <> 0) AndAlso (width > 1)) AndAlso (height > 1)) AndAlso (linewidth >= 1)) AndAlso (distance >= 0)) AndAlso (peakdelay >= 0) Then
            v_bitmap = Nothing
            v_graphics = Nothing
            v_pen = Nothing
            v_pen1 = Nothing
            Try
                Try
                    If l(channel, MaxFFT) > 0 Then
                        v_brush = New Drawing2D.LinearGradientBrush(New System.Drawing.Rectangle(0, 0, linewidth, height), color2, color1, Drawing2D.LinearGradientMode.Vertical)
                        Try
                            v_pen = New System.Drawing.Pen(v_brush, CSng(linewidth))
                            v_pen1 = New System.Drawing.Pen(color3, CSng(peakwidth))
                            v_bitmap = New System.Drawing.Bitmap(width, height)
                            v_graphics = System.Drawing.Graphics.FromImage(v_bitmap)
                            If highQuality Then
                                v_graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
                                v_graphics.CompositingQuality = Drawing2D.CompositingQuality.AssumeLinear
                                v_graphics.PixelOffsetMode = Not Drawing2D.PixelOffsetMode.Invalid
                                v_graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit
                            Else
                                v_graphics.SmoothingMode = Drawing2D.SmoothingMode.HighSpeed
                                v_graphics.CompositingQuality = Drawing2D.CompositingQuality.HighSpeed
                                v_graphics.PixelOffsetMode = Drawing2D.PixelOffsetMode.None
                                v_graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit
                            End If
                            l(v_graphics, width, height, v_pen, v_pen1, linewidth, distance, peakdelay, background, _
                              linear, fullSpectrum)
                        Finally
                            If Not v_brush Is Nothing Then
                                v_brush.Dispose()
                            End If
                        End Try
                    End If
                Catch
                    v_bitmap = Nothing
                End Try
            Finally
                If Not v_pen Is Nothing Then
                    v_pen.Dispose()
                End If
                If Not v_pen1 Is Nothing Then
                    v_pen1.Dispose()
                End If
                If Not v_graphics Is Nothing Then
                    v_graphics.Dispose()
                End If
            End Try
            Return v_bitmap
        Else
            Return Nothing
        End If
        Return v_bitmap
    End Function
    Private Shared Function l(ByVal A_0 As Integer, ByVal A_1 As Integer) As Integer
        If Not Visuals.c Then
            Return BASS_ChannelGetData(A_0, Visuals.a, A_1)
        End If
    End Function
    Private Shared Sub l(ByVal A_0 As System.Drawing.Graphics, ByVal A_1 As Integer, ByVal A_2 As Integer, ByVal A_3 As System.Drawing.Pen, ByVal A_4 As System.Drawing.Pen, ByVal A_5 As Integer, ByVal A_6 As Integer, ByVal A_7 As Integer, ByVal A_8 As System.Drawing.Color, ByVal A_9 As Boolean, ByVal A_10 As Boolean)
        Dim v_sng As Single
        Dim v_sng1 As Single
        Dim v_sng2 As Single
        Dim v_sng4 As Single
        Dim v_i As Integer
        A_0.Clear(A_8)
        Visuals.k = A_9
        v_sng = 0.0!
        v_sng1 = 0.0!
        v_sng2 = 0.0!
        v_sng4 = 0.0!
        Visuals.j = (CDbl(MaxFrequencySpectrum)) / (CDbl(A_1))
        v_i = MaxFrequencySpectrum + 1
        Visuals.j = 1
        v_i = A_1 + 1
        If (Not A_10) AndAlso (v_i > (MaxFFTSampleIndex + 1)) Then
            v_i = MaxFFTSampleIndex + 1
        End If
        For v_i1 As Integer = 1 To v_i - 1
            If A_9 Then
                v_sng2 = (Visuals.a(v_i1) * (CSng(ScaleFactorLinear))) * (CSng(A_2))
                If v_sng4 <= v_sng2 Then
                    v_sng4 = v_sng2
                End If
                v_sng4 = 0.0!
            Else
                v_sng2 = (((CSng(System.Math.Sqrt(CDbl(Visuals.a(v_i1))))) * (CSng(ScaleFactorSqr))) * (CSng(A_2))) - 4.0!
                If v_sng4 <= v_sng2 Then
                    v_sng4 = v_sng2
                End If
                If (v_sng4 <= 0.0!) AndAlso (v_sng4 <= 0.0!) Then
                    v_sng4 = 0.0!
                End If
            End If
            If v_sng4 > (CSng(A_2)) Then
                v_sng4 = CSng(A_2)
            End If
            v_sng = (CSng(System.Math.Round((CDbl(v_i1)) / Visuals.j))) - 1.0!
            If (((CInt(v_sng)) Mod (A_6 + A_5)) = 0) AndAlso (v_sng > v_sng1) Then
                v_sng4 = (v_sng4 + v_sng4) / 2.0!
                If Visuals.b(CInt(v_sng)) <= v_sng4 Then
                    Visuals.b(CInt(v_sng)) = v_sng4
                Else
                    Visuals.b(CInt(v_sng)) = (v_sng4 + ((CSng(A_7)) * Visuals.b(CInt(v_sng)))) / (CSng(A_7 + 1))
                End If
                A_0.DrawLine(A_3, (v_sng1 + (CSng(A_5 / 2))) + 1.0!, (CSng(A_2)) - 1.0!, (v_sng1 + (CSng(A_5 / 2))) + 1.0!, ((CSng(A_2)) - 1.0!) - v_sng4)
                A_0.DrawLine(A_4, v_sng1 + 1.0!, ((CSng(A_2)) - (A_4.Width / 2.0!)) - Visuals.b(CInt(v_sng)), ((v_sng1 + (CSng(A_5))) + (CSng(IIf(A_4.Width > 1.0!, 0, -1)))) + 1.0!, ((CSng(A_2)) - (A_4.Width / 2.0!)) - Visuals.b(CInt(v_sng)))
                v_sng1 = v_sng
                v_sng4 = 0.0!
            End If
        Next v_i1
    End Sub
    Private Shared Property ScaleFactorLinear() As Integer
        Get
            Return Visuals.d
        End Get
        Set(ByVal Value As Integer)
            Visuals.d = Value
        End Set
    End Property
    Private Shared Property ScaleFactorSqr() As Integer
        Get
            Return Visuals.e
        End Get
        Set(ByVal Value As Integer)
            Visuals.e = Value
        End Set
    End Property
    Private Shared ReadOnly Property MaxFFTSampleIndex() As Integer
        Get
            Return Visuals.g
        End Get
    End Property
    Private Shared Property MaxFFT() As BASSData
        Get
            Return Visuals.h
        End Get
        Set(ByVal Value As BASSData)
            Select Case Value
                Case BASSData.BASS_DATA_FFT512
                    Visuals.f = 1024
                    Visuals.h = Value
                    Visuals.g = 255
                Case BASSData.BASS_DATA_FFT1024
                    Visuals.f = 1024
                    Visuals.h = Value
                    Visuals.g = 511
                Case BASSData.BASS_DATA_FFT2048
                    Visuals.f = 2048
                    Visuals.h = Value
                    Visuals.g = 1023
                Case BASSData.BASS_DATA_FFT4096
                    Visuals.f = 4096
                    Visuals.h = Value
                    Visuals.g = 2047
                Case BASSData.BASS_DATA_FFT8192
                    Visuals.f = 8192
                    Visuals.h = Value
                    Visuals.g = 4095
                Case Else
                    Visuals.f = 4096
                    Visuals.h = BASSData.BASS_DATA_FFT4096
                    Visuals.g = 2047
                    If Visuals.i > Visuals.g Then
                        Visuals.i = Visuals.g
                    End If
                    Return
            End Select
        End Set
    End Property
    Private Shared Property MaxFrequencySpectrum() As Integer
        Get
            Return Visuals.i
        End Get
        Set(ByVal Value As Integer)
            If Value > MaxFFTSampleIndex Then
                Visuals.i = MaxFFTSampleIndex
            End If
            If Value >= 1 Then
                Visuals.i = Value
                Return
            End If
            Visuals.i = 1
        End Set
    End Property
    <Flags()> _
    Private Enum BASSData
        BASS_DATA_FFT8192 = -2147483643
        BASS_DATA_FFT4096 = -2147483644
        BASS_DATA_FFT2048 = -2147483645
        BASS_DATA_FFT1024 = -2147483646
        BASS_DATA_FFT512 = -2147483647
        BASS_DATA_FFT256 = -2147483648
    End Enum
    Public Shared Function SpecturmLineFree() As System.Drawing.Bitmap
        Return CreateSpectrumLinePeak(0, 0, 0, Color.Black, Color.Black, Color.Black, Color.Black, 0, 0, 0, 0, False, False, False)
    End Function
End Class

« Last Edit: 14 Dec '12 - 15:04 by sak2005 »

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #72 on: 14 Dec '12 - 15:05 »
Example: BassUn4Seen Spectrum Sound Player
Code: [Select]
Public Class Form1
    Declare Function BASS_Init Lib "bass.dll" (ByVal A_0 As Integer, ByVal A_1 As Integer, ByVal A_2 As BASSInit, ByVal A_3 As System.IntPtr, ByVal A_4 As System.IntPtr) As Boolean
    Declare Function BASS_StreamCreateFileUnicode Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal A_0 As Boolean, <Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal A_1 As String, ByVal A_2 As Long, ByVal A_3 As Long, ByVal A_4 As BASSFlag) As Integer
    Declare Function BASS_StreamFree Lib "bass.dll" (ByVal A_0 As Integer) As Boolean
    Declare Function BASS_ChannelPlay Lib "bass.dll" (ByVal A_0 As Integer, ByVal handle As Boolean) As Boolean
    Declare Function BASS_ChannelPause Lib "bass.dll" (ByVal A_0 As Integer) As Boolean
    Declare Function BASS_ChannelStop Lib "bass.dll" (ByVal handle As Integer) As Boolean
    Declare Function BASS_Start Lib "bass.dll" () As Boolean
    Declare Function BASS_Stop Lib "bass.dll" () As Boolean
    Declare Function BASS_ChannelGetLevel Lib "bass.dll" (ByVal handle As Integer) As Integer
    Declare Function BASS_ChannelGetData Lib "bass.dll" (ByVal handle As Integer, ByVal buffer As Single(), ByVal length As Integer) As Integer
    Declare Function BASS_ChannelSeconds2Bytes Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Double) As Long
    Declare Function BASS_ChannelBytes2Seconds Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Long) As Double
    Declare Function BASS_ChannelGetLength Lib "bass.dll" (ByVal handle As Integer, ByVal mode As BASSMode) As Long
    Declare Function BASS_ChannelGetPosition Lib "bass.dll" (ByVal handle As Integer, ByVal mode As BASSMode) As Long
    Declare Function BASS_ChannelSetPosition Lib "bass.dll" (ByVal A_0 As Integer, ByVal handle As Long, ByVal pos As BASSMode) As Boolean
    Declare Function BASS_GetVolume Lib "bass.dll" () As Single
    Declare Function BASS_SetVolume Lib "bass.dll" (ByVal A_0 As Single) As Boolean
    Private openFile As OpenFileDialog
    Private btnBrowse, btnPlay, btnStop As Button
    Private spectrum As New Visuals
    Private visBox As PictureBox
    Private timer1 As New Timer
    Private file As String
    Public strm As Integer
    Public Sub New()
        MyBase.New()
        InitializeComponent()
        Me.CenterToScreen()
        Me.Size = New Size(300, 240)
        Me.Text = "BassSoundPlayer"
        Me.MaximizeBox = False
        Me.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink
        openFile = New OpenFileDialog
        openFile.FileName = Nothing
        openFile.Filter = "Song file(*.mp3;*.wav|*.mp3;*.wav)"
        btnBrowse = New Button
        btnPlay = New Button
        btnStop = New Button
        visBox = New PictureBox
        btnBrowse.Text = "Load"
        btnPlay.Text = "Play"
        btnStop.Text = "Stop"
        btnBrowse.Location = New Point(10, 170)
        btnPlay.Location = New Point(105, 170)
        btnStop.Location = New Point(200, 170)
        btnBrowse.Cursor = Cursors.Hand
        btnPlay.Cursor = Cursors.Hand
        btnStop.Cursor = Cursors.Hand
        visBox.SetBounds(10, 10, 270, 140)
        visBox.BackColor = Color.Black
        Me.Controls.AddRange(New Control() {visBox, btnBrowse, btnPlay, btnStop})
        AddHandler btnBrowse.Click, AddressOf btnBrowse_Click
        AddHandler btnPlay.Click, AddressOf btnPlay_Click
        AddHandler btnStop.Click, AddressOf btnStop_Click
        AddHandler timer1.Tick, AddressOf timer1_Tick
        timer1.Interval = 40
    End Sub
    Public Function BASS_Init(ByVal device As Integer, ByVal freq As Integer, ByVal flags As BASSInit, ByVal win As System.IntPtr) As Boolean
        Return BASS_Init(device, freq, flags, win, System.IntPtr.Zero)
    End Function
    Public Function BASS_StreamCreateFile(ByVal [File] As String, ByVal offset As Long, ByVal length As Long, ByVal flags As BASSFlag) As Integer
        flags = flags Or BASSFlag.BASS_UNICODE
        Return BASS_StreamCreateFileUnicode(False, [File], offset, length, flags)
    End Function
    Public Function BASS_ChannelGetLength(ByVal handle As Integer) As Long
        Return BASS_ChannelGetLength(handle, BASSMode.BASS_POS_BYTES)
    End Function
    Public Function BASS_ChannelGetPosition(ByVal handle As Integer) As Long
        Return BASS_ChannelGetPosition(handle, BASSMode.BASS_POS_BYTES)
    End Function
    Public Function BASS_ChannelSetPosition(ByVal handle As Integer, ByVal pos As Long) As Boolean
        Return BASS_ChannelSetPosition(handle, pos, BASSMode.BASS_POS_BYTES)
    End Function
    Public Function FixTimespan(ByVal seconds As Double) As String
        Dim v_timeSpan As System.TimeSpan
        v_timeSpan = System.TimeSpan.FromSeconds(seconds)
        Return v_timeSpan.ToString
    End Function
    Public Function HighWord32(ByVal dWord As Integer) As Integer
        Return (dWord >> 16) And 65535
    End Function
    Public Function LowWord32(ByVal dWord As Integer) As Integer
        Return dWord And 65535
    End Function
    <Flags()> _
    Public Enum BASSFlag
        BASS_DEFAULT = 0
        BASS_SAMPLE_FLOAT = 256
        BASS_STREAM_PRESCAN = 131072
        BASS_STREAM_AUTOFREE = 262144
        BASS_STREAM_STATUS = 8388608
        BASS_UNICODE = -2147483648
        BASS_MUSIC_LOOP = 4
        BASS_MUSIC_AUTOFREE = 262144
        BASS_MUSIC_PRESCAN = 131072
        BASS_MUSIC_POSRESET = 32768
    End Enum
    <Flags()> _
    Public Enum BASSInit
        BASS_DEVICE_DEFAULT = 0
        BASS_DEVICE_CPSPEAKERS = 1024
        BASS_DEVICE_SPEAKERS = 2048
        BASS_DEVICE_NOSPEAKER = 4096
        BASS_DEVICE_FREQ = 16384
    End Enum
    <Flags()> _
    Public Enum BASSMode
        BASS_POS_BYTES = 0
        BASS_POS_MUSIC_ORDERS = 1
        BASS_MUSIC_POSRESET = 32768
        BASS_MUSIC_POSRESETEX = 4194304
    End Enum
    Private Sub btnBrowse_Click(ByVal sender As Object, ByVal e As EventArgs)
        If openFile.ShowDialog = Windows.Forms.DialogResult.OK Then
            BASS_StreamFree(strm)
            file = openFile.FileName
            strm = BASS_StreamCreateFile(file, 0, 0, 0)
        End If
    End Sub
    Private Sub btnPlay_Click(ByVal sender As Object, ByVal e As EventArgs)
        BASS_ChannelPlay(strm, True)
        timer1.Enabled = True
    End Sub
    Private Sub btnStop_Click(ByVal sender As Object, ByVal e As EventArgs)
        BASS_ChannelStop(strm)
        timer1.Enabled = False
        visBox.Image = Visuals.SpecturmLineFree()
    End Sub
    Private Sub timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
        visBox.Image = Visuals.CreateSpectrumLinePeak(strm, visBox.Width, visBox.Height, Color.Green, Color.Red, Color.White, Color.Black, 4, 2, 1, 20, False, False, True)
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            BASS_Init(-1, 44100, 0, Me.Handle.ToInt32)
        Catch ex As Exception
            MsgBox(ex.Message & vbCrLf & "You must add file bass.dll in to the debug folder.", 48, "Error!")
            Me.Dispose()
        End Try
    End Sub
End Class

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #73 on: 16 Dec '12 - 08:50 »
Get file: ProgressBarGradient.dll Click here

Example:
Code: [Select]
Public Class Form1
    Declare Function BASS_Init Lib "bass.dll" (ByVal A_0 As Integer, ByVal A_1 As Integer, ByVal A_2 As BASSInit, ByVal A_3 As System.IntPtr, ByVal A_4 As System.IntPtr) As Boolean
    Declare Function BASS_StreamCreateFileUnicode Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal A_0 As Boolean, <Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal A_1 As String, ByVal A_2 As Long, ByVal A_3 As Long, ByVal A_4 As BASSFlag) As Integer
    Declare Function BASS_StreamFree Lib "bass.dll" (ByVal A_0 As Integer) As Boolean
    Declare Function BASS_ChannelPlay Lib "bass.dll" (ByVal A_0 As Integer, ByVal handle As Boolean) As Boolean
    Declare Function BASS_ChannelStop Lib "bass.dll" (ByVal handle As Integer) As Boolean
    Declare Function BASS_ChannelGetLevel Lib "bass.dll" (ByVal handle As Integer) As Integer
    Private openFile As New OpenFileDialog
    Private btnBrowse, btnPlay, btnStop As New Button
    Private timer1 As New Timer
    Private file As String
    Public strm As Integer
    Public Sub New()
        MyBase.New()
        InitializeComponent()
        Me.CenterToScreen()
        Me.Size = New Size(292, 250)
        Me.Text = "BassUn4SeenProgressBarGradient"
        Me.MaximizeBox = False
        Me.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink
        openFile.FileName = Nothing
        openFile.Filter = "Song file(*.mp3;*.wav|*.mp3;*.wav)"
        btnBrowse.Text = "Load"
        btnPlay.Text = "Play"
        btnStop.Text = "Stop"
        btnBrowse.Location = New Point(10, 185)
        btnPlay.Location = New Point(105, 185)
        btnStop.Location = New Point(200, 185)
        btnBrowse.ForeColor = Color.White
        btnPlay.ForeColor = Color.White
        btnStop.ForeColor = Color.White
        btnBrowse.Cursor = Cursors.Hand
        btnPlay.Cursor = Cursors.Hand
        btnStop.Cursor = Cursors.Hand
        ProgressBarGradient1.BorderStyle = BorderStyle.FixedSingle
        ProgressBarGradient2.BorderStyle = BorderStyle.FixedSingle
        ProgressBarGradient3.BorderStyle = BorderStyle.FixedSingle
        ProgressBarGradient4.BorderStyle = BorderStyle.FixedSingle
        ProgressBarGradient1.MidColorPosition = 0.6
        ProgressBarGradient2.MidColorPosition = 0.6
        ProgressBarGradient3.MidColorPosition = 0.6
        ProgressBarGradient4.MidColorPosition = 0.6
        ProgressBarGradient1.Orientation = Orientation.Vertical
        ProgressBarGradient2.Orientation = Orientation.Vertical
        ProgressBarGradient3.Orientation = Orientation.Horizontal
        ProgressBarGradient4.Orientation = Orientation.Horizontal 
        timer1.Interval = 40
        Me.Controls.AddRange(New Control() {btnBrowse, btnPlay, btnStop})
        AddHandler btnBrowse.Click, AddressOf btnBrowse_Click
        AddHandler btnPlay.Click, AddressOf btnPlay_Click
        AddHandler btnStop.Click, AddressOf btnStop_Click
        AddHandler timer1.Tick, AddressOf timer1_Tick
    End Sub
    Public Function HighWord32(ByVal dWord As Integer) As Integer
        Return (dWord >> 16) And 65535
    End Function
    Public Function LowWord32(ByVal dWord As Integer) As Integer
        Return dWord And 65535
    End Function
    <Flags()> _
    Public Enum BASSFlag
        BASS_DEFAULT = 0
        BASS_UNICODE = -2147483648
    End Enum
    <Flags()> _
    Public Enum BASSInit
        BASS_DEVICE_DEFAULT = 0
    End Enum
    <Flags()> _
    Public Enum BASSMode
        BASS_POS_BYTES = 0
    End Enum
    Private Sub btnBrowse_Click(ByVal sender As Object, ByVal e As EventArgs)
        If openFile.ShowDialog = Windows.Forms.DialogResult.OK Then
            BASS_StreamFree(strm)
            file = openFile.FileName
            strm = BASS_StreamCreateFileUnicode(False, file, 0, 0, BASSFlag.BASS_UNICODE Or BASSFlag.BASS_DEFAULT)
            ProgressBarGradient1.Value = ProgressBarGradient1.MinimumValue
            ProgressBarGradient2.Value = ProgressBarGradient2.MinimumValue
            ProgressBarGradient3.Value = ProgressBarGradient3.MinimumValue
            ProgressBarGradient4.Value = ProgressBarGradient4.MinimumValue
        End If
    End Sub
    Private Sub btnPlay_Click(ByVal sender As Object, ByVal e As EventArgs)
        BASS_ChannelPlay(strm, True)
        timer1.Enabled = True
    End Sub
    Private Sub timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
        Dim Lev As Integer = BASS_ChannelGetLevel(strm)
        Dim peakL As Integer = HighWord32(Lev)
        Dim peakR As Integer = LowWord32(Lev)
        Try
            ProgressBarGradient1.Value = LevelCurrentProgress(peakL)
            ProgressBarGradient2.Value = LevelCurrentProgress(peakR)
            ProgressBarGradient3.Value = LevelCurrentProgress(peakL)
            ProgressBarGradient4.Value = LevelCurrentProgress(peakR)
            Catch ex As Exception
        End Try
    End Sub
    Private Sub btnStop_Click(ByVal sender As Object, ByVal e As EventArgs)
        BASS_ChannelStop(strm)
        ProgressBarGradient1.Value = ProgressBarGradient1.MinimumValue
        ProgressBarGradient2.Value = ProgressBarGradient2.MinimumValue
        ProgressBarGradient3.Value = ProgressBarGradient3.MinimumValue
        ProgressBarGradient4.Value = ProgressBarGradient4.MinimumValue
        timer1.Enabled = False
    End Sub
    Private Function LevelCurrentProgress(ByVal peak As Integer) As Double
        Dim v_peak As Double
        Try
            v_peak = (peak / 33525) * 100
        Catch ex As Exception
        End Try
        Return v_peak
    End Function
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            BASS_Init(-1, 44100, 0, Me.Handle.ToInt32, System.IntPtr.Zero)
        Catch ex As Exception
            MsgBox(ex.Message & vbCrLf & "You must add file bass.dll in to the debug folder.", 48, "Error!")
            Me.Dispose()
        End Try
    End Sub
End Class
« Last Edit: 16 Dec '12 - 09:06 by sak2005 »

sak2005

  • Posts: 911
Re: Direct bass : Vb.net
« Reply #74 on: 16 Dec '12 - 13:43 »
Get code: Creatting  LED Level Meter ;D

3 class for creatting usercontrol component compile to a VuMeter.net.dll

« Last Edit: 17 Dec '12 - 10:24 by sak2005 »