Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion iBMSC/Audio.vb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,37 @@ Module Audio
Dim Output As WasapiOut
Dim Source As IWaveSource

Public Structure BMSONSliceResult
Public Found As Boolean
Public Start As Double
Public Length As Double
Public Overrides Function ToString() As String
Return "Slice result " & Found & " - " & Start & " => " & Length
End Function
End Structure

' https://github.com/filoe/cscore/blob/master/CSCore.Test/utils/TrimmedWaveSource.cs
Public Class TrimmedWaveSource
Inherits WaveAggregatorBase
Private mSource As IWaveSource
Private mMaxLength As Integer
Private mRead As Integer
Public Sub New(Source As IWaveSource, MaxLength As Integer)
MyBase.New(Source)
mSource = Source
mMaxLength = MaxLength
End Sub
Public Overrides Function Read(buffer() As Byte, offset As Integer, count As Integer) As Integer
Dim ReadBytes = MyBase.Read(buffer, offset, count)
mRead = mRead + ReadBytes
If mRead > mMaxLength Then
ReadBytes = ReadBytes - (mRead - mMaxLength)
mRead = mMaxLength
End If
Return ReadBytes
End Function
End Class

Public Sub Initialize()
Output = New WasapiOut()
CodecFactory.Instance.Register("ogg", New CodecFactoryEntry(Function(s)
Expand Down Expand Up @@ -36,7 +67,7 @@ Module Audio
Return filename
End Function

Public Sub Play(ByVal filename As String)
Public Sub Play(ByVal filename As String, ByVal slice As BMSONSliceResult)

If Source IsNot Nothing Then
Output.Stop()
Expand All @@ -55,10 +86,21 @@ Module Audio
End If

Source = CodecFactory.Instance.GetCodec(fn)
If slice.Found Then
Source.Position = Source.WaveFormat.MillisecondsToBytes(Conversion.Int(slice.Start))
If slice.Length > 0 Then
Source = New TrimmedWaveSource(Source, Source.WaveFormat.MillisecondsToBytes(Conversion.Int(slice.Length)))
End If
End If
Output.Initialize(Source)
Output.Play()
End Sub

Public Sub Play(ByVal filename As String)
Dim slice As BMSONSliceResult
Play(filename, slice)
End Sub

Public Sub StopPlaying()
Output.Stop()
End Sub
Expand Down
9 changes: 6 additions & 3 deletions iBMSC/MainWindow.vb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ Imports iBMSC.Editor


Public Class MainWindow


'Public Structure MARGINS
' Public Left As Integer
' Public Right As Integer
Expand Down Expand Up @@ -486,10 +484,15 @@ Public Class MainWindow
End Sub

Private Sub PreviewNote(ByVal xFileLocation As String, ByVal bStop As Boolean)
Dim Slice As BMSONSliceResult
Audio.Play(xFileLocation, Slice)
End Sub

Private Sub PreviewNote(ByVal xFileLocation As String, ByVal bStop As Boolean, ByVal Slice As BMSONSliceResult)
If bStop Then
Audio.StopPlaying()
End If
Audio.Play(xFileLocation)
Audio.Play(xFileLocation, Slice)
End Sub

Private Sub AddNote(note As Note,
Expand Down
26 changes: 19 additions & 7 deletions iBMSC/PanelDraw.vb
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,23 @@ Partial Public Class MainWindow
End If
End Sub

Private Function GetNoteLabel(sNote As Note)
Dim xLabel As String = C10to36(sNote.Value \ 10000)
Dim xContinue As Boolean = False
Dim xWAV As String = hWAV(sNote.Value \ 10000)
If xWAV <> "" AndAlso xWAV.Length = 4 AndAlso xWAV.Substring(0, 2) = "C-" Then
xLabel = xWAV.Substring(2)
xContinue = True
End If
If ShowFileName AndAlso hWAV(C36to10(xLabel)) <> "" Then
xLabel = Path.GetFileNameWithoutExtension(hWAV(C36to10(xLabel)))
End If
If xContinue Then
xLabel = ">" & xLabel
End If
Return xLabel
End Function

''' <summary>
''' Draw a note in a buffer.
''' </summary>
Expand All @@ -450,10 +467,7 @@ Partial Public Class MainWindow
Dim xAlpha As Single = 1.0F
If sNote.Hidden Then xAlpha = vo.kOpacity

Dim xLabel As String = C10to36(sNote.Value \ 10000)
If ShowFileName AndAlso hWAV(C36to10(xLabel)) <> "" Then
xLabel = Path.GetFileNameWithoutExtension(hWAV(C36to10(xLabel)))
End If
Dim xLabel As String = GetNoteLabel(sNote)

Dim xPen As Pen
Dim xBrush As Drawing2D.LinearGradientBrush
Expand Down Expand Up @@ -555,9 +569,7 @@ Partial Public Class MainWindow
Dim xAlpha As Single = 1.0F
If sNote.Hidden Then xAlpha = vo.kOpacity

Dim xLabel As String = C10to36(sNote.Value \ 10000)
If ShowFileName AndAlso hWAV(C36to10(xLabel)) <> "" Then xLabel = Path.GetFileNameWithoutExtension(hWAV(C36to10(xLabel)))

Dim xLabel As String = GetNoteLabel(sNote)
Dim xPen1 As Pen
Dim xBrush As Drawing2D.LinearGradientBrush
Dim xBrush2 As SolidBrush
Expand Down
67 changes: 65 additions & 2 deletions iBMSC/PanelEvents.vb
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,54 @@ MoveToColumn: If xTargetColumn = -1 Then Exit Select
Return NoteIndex
End Function

Private Function GetBMSONSliceTime(NoteIndex As Integer, ContinueI2 As Integer, StartI2 As Integer) As BMSONSliceResult
Dim currentMS = 0.0#
Dim currentBPM = Notes(0).Value / 10000
Dim currentBPMVPosition = 0.0#
Dim startTime = 0.0#
Dim sliceStart = 0.0#
Dim sliceEnd = 0.0#
Dim started = False
Dim found As Integer = -1
Dim result As BMSONSliceResult
For i = 1 To UBound(Notes)
If Notes(i).ColumnIndex = niBPM Then
currentMS += (Notes(i).VPosition - currentBPMVPosition) / currentBPM * 1250
currentBPM = Notes(i).Value / 10000
currentBPMVPosition = Notes(i).VPosition
End If

If i = NoteIndex Then
If found = -1 Then
result.Found = False
Return result
End If
sliceStart = currentMS + (Notes(i).VPosition - currentBPMVPosition) / currentBPM * 1250
started = True
ElseIf started And (Notes(i).Value \ 10000 = StartI2 Or Notes(i).Value \ 10000 = ContinueI2) Then
sliceEnd = currentMS + (Notes(i).VPosition - currentBPMVPosition) / currentBPM * 1250
If sliceEnd > sliceStart Then
result.Found = True
result.Start = sliceStart - startTime
result.Length = sliceEnd - sliceStart
Return result
End If
ElseIf Notes(i).Value \ 10000 = StartI2 And Not started Then
found = i
startTime = currentMS + (Notes(i).VPosition - currentBPMVPosition) / currentBPM * 1250
End If
'K(i).TimeOffset = currentMS + (K(i).VPosition - currentBPMVPosition) / currentBPM * 1250
Next
If found Then
result.Found = True
result.Start = sliceStart - startTime
result.Length = 0
Return result
End If
result.Found = False
Return result
End Function

Private Sub PanelPreviewNoteIndex(NoteIndex As Integer)
'Play wav
If ClickStopPreview Then PreviewNote("", True)
Expand All @@ -449,9 +497,24 @@ MoveToColumn: If xTargetColumn = -1 Then Exit Select
If xI2 >= 1296 Then xI2 = 1295

If Not hWAV(xI2) = "" Then ' AndAlso Path.GetExtension(hWAV(xI2)).ToLower = ".wav" Then
Dim xFileLocation As String = IIf(ExcludeFileName(FileName) = "", InitPath, ExcludeFileName(FileName)) & "\" & hWAV(xI2)
Dim xFileName As String = hWAV(xI2)
Dim xFileLocation As String = IIf(ExcludeFileName(FileName) = "", InitPath, ExcludeFileName(FileName)) & "\" & xFileName
Dim Slice As BMSONSliceResult
If xFileName.Length = 4 And xFileName.Substring(0, 2) = "C-" Then
Dim TargetI2 = C36to10(xFileName.Substring(2))
Dim TargetFileName As String = hWAV(TargetI2)
If Not TargetFileName = "" Then
Dim TargetFileLocation = IIf(ExcludeFileName(FileName) = "", InitPath, ExcludeFileName(FileName)) & "\" & TargetFileName
Slice = GetBMSONSliceTime(NoteIndex, xI2, TargetI2)
If slice.Found Then
xFileLocation = TargetFileLocation
End If
End If
End If
If Not ClickStopPreview Then PreviewNote("", True)
PreviewNote(xFileLocation, False)
Console.WriteLine(xFileLocation)
Console.WriteLine(Slice)
PreviewNote(xFileLocation, False, Slice)
End If
End If
End Sub
Expand Down