You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
421 lines
14 KiB
421 lines
14 KiB
Imports System.Runtime.InteropServices |
|
Imports System.Text |
|
Imports System.Text.RegularExpressions |
|
Imports System.IO |
|
Imports Un4seen.Bass |
|
Imports CDGNet |
|
Imports Un4seen.Bass.AddOn.Fx |
|
Imports System.Data.SQLite |
|
Imports MetroFramework.Forms |
|
|
|
|
|
Public Class Form1 |
|
Inherits MetroFramework.Forms.MetroForm |
|
|
|
#Region "Private Declarations" |
|
|
|
Private mCDGFile As CDGFile |
|
Private mCDGStream As CdgFileIoStream |
|
Private mSemitones As Integer = 0 |
|
Private mPaused As Boolean |
|
Private mFrameCount As Long = 0 |
|
Private mStop As Boolean |
|
Private mCDGFileName As String |
|
Private mMP3FileName As String |
|
Private mytempo As String |
|
Private mTempDir As String |
|
Private mMP3Stream As Integer |
|
Private WithEvents mCDGWindow As New CDGWindow |
|
'Private WithEvents mPreviewWindow As New PreviewWindow |
|
Private mBassInitalized As Boolean = False |
|
|
|
#End Region |
|
|
|
#Region "Control Events" |
|
|
|
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
|
'Add registration key here if you have a license |
|
BassNet.Registration("buddyknox@usa.org", "2X11841782815") |
|
Try |
|
Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, Me.Handle) |
|
mBassInitalized = True |
|
|
|
Catch ex As Exception |
|
MsgBox("Unable to initialize the audio playback system.") |
|
End Try |
|
|
|
If System.IO.File.Exists(Application.StartupPath + "\karaoke.db") Then |
|
Else |
|
CreateDB() |
|
End If |
|
|
|
|
|
Dim frm As New LoadingForm() |
|
frm.Show() |
|
GetFiles() |
|
For Each arg As String In My.Application.CommandLineArgs |
|
tbFileName.Text = arg |
|
tsbPlay.PerformClick() |
|
Next |
|
frm.Hide() |
|
|
|
|
|
|
|
|
|
|
|
End Sub |
|
|
|
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btBrowse.Click |
|
BrowseCDGZip() |
|
End Sub |
|
|
|
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed |
|
StopPlayback() |
|
End Sub |
|
|
|
Private Sub tsbPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbPlay.Click |
|
Play() |
|
End Sub |
|
|
|
Private Sub tsbStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbStop.Click |
|
Try |
|
StopPlayback() |
|
Catch ex As Exception |
|
'Do nothing for now |
|
End Try |
|
End Sub |
|
|
|
Private Sub tsbPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbPause.Click |
|
Pause() |
|
End Sub |
|
|
|
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles trbVolume.Scroll |
|
AdjustVolume() |
|
End Sub |
|
|
|
Private Sub nudKey_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudKey.ValueChanged |
|
AdjustPitch() |
|
End Sub |
|
Private Sub nudtempo_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudKey.ValueChanged, nudtempo.ValueChanged |
|
AdjustTempo() |
|
End Sub |
|
|
|
Private Sub mCDGWindow_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles mCDGWindow.FormClosing |
|
StopPlayback() |
|
mCDGWindow.Hide() |
|
e.Cancel = True |
|
End Sub |
|
|
|
'Private Sub mPreviewWindow_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles mPreviewWindow.FormClosing |
|
'StopPlayback() |
|
' mPreviewWindow.Hide() |
|
' e.Cancel = True |
|
' End Sub |
|
|
|
#End Region |
|
|
|
#Region "CDG + MP3 Playback Operations" |
|
|
|
Private Sub Pause() |
|
mPaused = Not mPaused |
|
If mMP3Stream <> 0 Then |
|
If Bass.BASS_ChannelIsActive(mMP3Stream) <> BASSActive.BASS_ACTIVE_PLAYING Then |
|
Bass.BASS_ChannelPlay(mMP3Stream, False) |
|
tsbPause.Text = "Pause" |
|
Else |
|
Bass.BASS_ChannelPause(mMP3Stream) |
|
tsbPause.Text = "Resume" |
|
End If |
|
End If |
|
End Sub |
|
|
|
Private Sub PlayMP3Bass(ByVal mp3FileName As String) |
|
If mBassInitalized OrElse Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, Me.Handle) Then |
|
mMP3Stream = 0 |
|
mMP3Stream = Bass.BASS_StreamCreateFile(mp3FileName, 0, 0, BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT Or BASSFlag.BASS_STREAM_PRESCAN) |
|
mMP3Stream = AddOn.Fx.BassFx.BASS_FX_TempoCreate(mMP3Stream, BASSFlag.BASS_FX_FREESOURCE Or BASSFlag.BASS_SAMPLE_FLOAT Or BASSFlag.BASS_SAMPLE_LOOP) |
|
If mMP3Stream <> 0 Then |
|
AdjustPitch() |
|
AdjustTempo() |
|
AdjustVolume() |
|
ShowCDGWindow() |
|
Bass.BASS_ChannelPlay(mMP3Stream, False) |
|
Else |
|
Throw New Exception(String.Format("Stream error: {0}", Bass.BASS_ErrorGetCode())) |
|
End If |
|
End If |
|
End Sub |
|
|
|
Private Sub StopPlaybackBass() |
|
Bass.BASS_Stop() |
|
Bass.BASS_StreamFree(mMP3Stream) |
|
Bass.BASS_Free() |
|
mMP3Stream = 0 |
|
mBassInitalized = False |
|
End Sub |
|
|
|
Public Sub StopPlayback() |
|
mStop = True |
|
HideCDGWindow() |
|
StopPlaybackBass() |
|
|
|
Try |
|
mCDGFile.Dispose() |
|
Catch ex As Exception |
|
End Try |
|
|
|
CleanUp() |
|
End Sub |
|
|
|
Private Sub PausePlayback() |
|
Bass.BASS_Pause() |
|
End Sub |
|
|
|
Private Sub ResumePlayback() |
|
Bass.BASS_Pause() |
|
End Sub |
|
|
|
Private Sub Play() |
|
Try |
|
If mMP3Stream <> 0 AndAlso Bass.BASS_ChannelIsActive(mMP3Stream) = BASSActive.BASS_ACTIVE_PLAYING Then |
|
StopPlayback() |
|
End If |
|
PreProcessFiles() |
|
If mCDGFileName = "" Or mMP3FileName = "" Then |
|
MsgBox("Cannot find a CDG and MP3 file to play together.") |
|
StopPlayback() |
|
Exit Sub |
|
End If |
|
mPaused = False |
|
mStop = False |
|
mFrameCount = 0 |
|
mCDGFile = New CDGFile(mCDGFileName) |
|
Dim cdgLength As Long = mCDGFile.getTotalDuration |
|
PlayMP3Bass(mMP3FileName) |
|
Dim startTime As DateTime = Now |
|
Dim endTime = startTime.AddMilliseconds(mCDGFile.getTotalDuration) |
|
Dim millisecondsRemaining As Long = cdgLength |
|
While millisecondsRemaining > 0 |
|
If mStop Then |
|
Exit While |
|
End If |
|
millisecondsRemaining = endTime.Subtract(Now).TotalMilliseconds |
|
Dim pos As Long = cdgLength - millisecondsRemaining |
|
While mPaused |
|
endTime = Now.AddMilliseconds(millisecondsRemaining) |
|
Application.DoEvents() |
|
End While |
|
' mCDGFile.renderAtPosition(pos) -- Old Value |
|
mCDGFile.renderAtPosition(pos + (nudtempo.Value * 150)) 'change 1/10 of a second each value |
|
mFrameCount += 1 |
|
|
|
|
|
mCDGWindow.PictureBox1.Image = mCDGFile.RGBImage |
|
mCDGWindow.PictureBox1.BackColor = CType(mCDGFile.RGBImage, Bitmap).GetPixel(1, 1) |
|
mCDGWindow.PictureBox1.Refresh() |
|
|
|
|
|
|
|
'mPreviewWindow.PictureBox1.Image = mCDGFile.RGBImage |
|
'mPreviewWindow.PictureBox1.BackColor = CType(mCDGFile.RGBImage, Bitmap).GetPixel(1, 1) |
|
'mPreviewWindow.PictureBox1.Refresh() |
|
|
|
|
|
|
|
Dim myFrameRate As Single = Math.Round(mFrameCount / (pos / 1000), 1) |
|
|
|
Application.DoEvents() |
|
End While |
|
|
|
StopPlayback() |
|
Catch ex As Exception |
|
End Try |
|
End Sub |
|
|
|
Private Sub AdjustPitch() |
|
If mMP3Stream <> 0 Then |
|
Bass.BASS_ChannelSetAttribute(mMP3Stream, BASSAttribute.BASS_ATTRIB_TEMPO_PITCH, nudKey.Value) |
|
End If |
|
End Sub |
|
Private Sub RemovalVocals() |
|
If mMP3Stream <> 0 Then |
|
'Bass.BASS_ChannelSetAttribute(mMP3Stream, Musi, nudKey.Value) |
|
End If |
|
End Sub |
|
|
|
Private Sub AdjustTempo() |
|
If mMP3Stream <> 0 Then |
|
Bass.BASS_ChannelSetAttribute(mMP3Stream, BASSAttribute.BASS_ATTRIB_TEMPO, nudtempo.Value) |
|
End If |
|
End Sub |
|
|
|
Private Sub AdjustVolume() |
|
If mMP3Stream <> 0 Then |
|
Bass.BASS_ChannelSetAttribute(mMP3Stream, BASSAttribute.BASS_ATTRIB_VOL, If(trbVolume.Value = 0, 0, (trbVolume.Value / 100))) |
|
End If |
|
End Sub |
|
#End Region |
|
|
|
#Region "Database Operations" |
|
|
|
Private Sub dbImport_Click(sender As System.Object, e As System.EventArgs) Handles dbImport.Click |
|
Dim importdb = New Import |
|
importdb.ShowDialog() |
|
GetFiles() |
|
|
|
End Sub |
|
|
|
Private Sub CreateDB() |
|
SQLiteConnection.CreateFile(Application.StartupPath + "\karaoke.db") |
|
Dim sqlConnection As New SQLite.SQLiteConnection() |
|
Dim sqlCommand As New SQLiteCommand("", sqlConnection) |
|
|
|
sqlConnection.ConnectionString = "Data Source=" + Application.StartupPath + "\karaoke.db" |
|
sqlConnection.Open() |
|
sqlCommand.CommandText = "CREATE TABLE karaoke(id INTEGER PRIMARY KEY ASC, song VCHAR(1000), location VCHAR(1000));" |
|
sqlCommand.ExecuteNonQuery() |
|
|
|
End Sub |
|
|
|
|
|
#End Region |
|
|
|
#Region "File Access" |
|
|
|
Private Sub BrowseCDGZip() |
|
OpenFileDialog1.Filter = "CDG or Zip Files (*.zip, *.cdg)|*.zip;*.cdg" |
|
OpenFileDialog1.ShowDialog() |
|
tbFileName.Text = OpenFileDialog1.FileName |
|
End Sub |
|
|
|
Private Sub PreProcessFiles() |
|
Dim myCDGFileName As String = "" |
|
If Regex.IsMatch(tbFileName.Text, "\.zip$") Then |
|
Dim myTempDir As String = Path.GetTempPath & Path.GetRandomFileName |
|
Directory.CreateDirectory(myTempDir) |
|
mTempDir = myTempDir |
|
myCDGFileName = Unzip.UnzipMP3GFiles(tbFileName.Text, myTempDir) |
|
GoTo PairUpFiles |
|
ElseIf Regex.IsMatch(tbFileName.Text, "\.cdg$") Then |
|
myCDGFileName = tbFileName.Text |
|
PairUpFiles: |
|
Dim myMP3FileName As String = RegularExpressions.Regex.Replace(myCDGFileName, "\.cdg$", ".mp3") |
|
If File.Exists(myMP3FileName) Then |
|
mMP3FileName = myMP3FileName |
|
mCDGFileName = myCDGFileName |
|
mTempDir = "" |
|
End If |
|
End If |
|
End Sub |
|
|
|
Private Sub CleanUp() |
|
If mTempDir <> "" Then |
|
Try |
|
Directory.Delete(mTempDir, True) |
|
Catch ex As Exception |
|
End Try |
|
End If |
|
mTempDir = "" |
|
End Sub |
|
|
|
#End Region |
|
|
|
#Region "CDG Graphics Window" |
|
|
|
Private Sub ShowCDGWindow() |
|
mCDGWindow.Show() |
|
'mPreviewWindow.Show() |
|
End Sub |
|
|
|
Private Sub HideCDGWindow() |
|
mCDGWindow.PictureBox1.Image = Nothing |
|
'mPreviewWindow.PictureBox1.Image = Nothing |
|
mCDGWindow.Hide() |
|
'mPreviewWindow.Hide() |
|
End Sub |
|
|
|
#End Region |
|
|
|
Private Sub GetFiles() |
|
|
|
|
|
Dim SQLconnect As New SQLite.SQLiteConnection() |
|
Dim SQLcommand As SQLiteCommand |
|
SQLconnect.ConnectionString = "Data Source=" + Application.StartupPath + "\karaoke.db" |
|
SQLconnect.Open() |
|
SQLcommand = SQLconnect.CreateCommand |
|
SQLcommand.CommandText = "SELECT * FROM karaoke" |
|
Dim SQLreader As SQLiteDataReader = SQLcommand.ExecuteReader() |
|
|
|
DataGridView1.ClearSelection() |
|
|
|
|
|
While SQLreader.Read() |
|
DataGridView1.Rows.Add(SQLreader(0), SQLreader(1), SQLreader(2)) |
|
End While |
|
|
|
SQLcommand.Dispose() |
|
SQLconnect.Close() |
|
|
|
|
|
'Dim firstNode As New TreeNode("Karaoke") |
|
'firstNode.Name = "CDG" |
|
'TreeView1.Nodes.Add(firstNode) |
|
|
|
'Dim dirPath As DirectoryInfo = New DirectoryInfo("Y:\OCS-Creations\") |
|
'For Each file As FileInfo In dirPath.GetFiles("*.cdg*", SearchOption.AllDirectories) |
|
'Dim n1 As New TreeNode(File.Name) |
|
'n1.Name = File.Name |
|
'n1.Tag = File.FullName |
|
'TreeView1.Nodes("CDG").Nodes.Add(n1) |
|
'Next |
|
End Sub |
|
|
|
Private Sub TreeView1_NodeMouseDoubleClick_1(sender As System.Object, e As System.Windows.Forms.TreeNodeMouseClickEventArgs) |
|
If e.Node.Tag <> "" Then |
|
tbFileName.Text = e.Node.Tag.ToString |
|
tsbPlay.PerformClick() |
|
End If |
|
End Sub |
|
|
|
|
|
Private Sub DataGridView1_CellDoubleClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick |
|
Dim row As Int32 = DataGridView1.CurrentCell.RowIndex |
|
Dim value As [String] = DataGridView1.Rows(row).Cells(2).Value.ToString() |
|
|
|
tbFileName.Text = value |
|
tsbPlay.PerformClick() |
|
|
|
|
|
End Sub |
|
|
|
Private Sub SearchButton_Click(sender As System.Object, e As System.EventArgs) Handles SearchButton.Click |
|
|
|
Dim SQLconnect As New SQLite.SQLiteConnection() |
|
Dim SQLcommand As SQLiteCommand |
|
SQLconnect.ConnectionString = "Data Source=" + Application.StartupPath + "\karaoke.db" |
|
SQLconnect.Open() |
|
SQLcommand = SQLconnect.CreateCommand |
|
SQLcommand.CommandText = "SELECT * FROM karaoke WHERE song LIKE '%" & SearchBox.Text & "%'" |
|
Dim SQLreader As SQLiteDataReader = SQLcommand.ExecuteReader() |
|
|
|
DataGridView1.Rows.Clear() |
|
|
|
|
|
While SQLreader.Read() |
|
DataGridView1.Rows.Add(SQLreader(0), SQLreader(1), SQLreader(2)) |
|
End While |
|
|
|
SQLcommand.Dispose() |
|
SQLconnect.Close() |
|
|
|
End Sub |
|
|
|
Private Sub SearchBox_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles SearchBox.KeyDown |
|
If e.KeyCode = Keys.Enter Then |
|
e.SuppressKeyPress = True |
|
SearchButton.PerformClick() |
|
|
|
End If |
|
End Sub |
|
End Class
|
|
|