使用 BinaryReader 读取 MIDI 文件。 (。网)

发布于 2024-11-01 03:32:27 字数 1135 浏览 0 评论 0原文

如何使用 BinaryReader 读取 midi 文件(格式规范位于此处

我正在使用 vb.net,但我愿意看到其他代码(主要是 C#,我可以转换它)。我正在开展一个大型项目,这有点阻碍。

这是我当前的代码:

Private Function convertCharArrayToString(ByVal chars() As Char) As String
    Dim tReturn As String = ""
    For Each v As Char In chars
        tReturn &= v
    Next
    Return tReturn
End Function

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    midiStatus = "Reading..."
    Dim midiStream As New StreamReader(midiFile)
    Dim nBR As New BinaryReader(midiStream.BaseStream)
    midiStatus = "Validating Midi File..."
    Dim HeaderA As String = convertCharArrayToString(nBR.ReadChars(4))
    If Not HeaderA = "MThd" Then Return
    Dim HeaderB() As Byte = nBR.ReadBytes(4)
    'Get Track Type
    midiStatus = "Reading Header Data..."
    Dim TrackType1 As Integer = nBR.ReadInt16()
    Dim TrackType2 As Integer = nBR.ReadInt16()
    MsgBox(TrackType1 & TrackType2)

End Sub

直到我开始阅读实际的标题数据时,一切都正常。我完全不知道该如何继续。任何帮助或代码示例都会很好!

How would I use a BinaryReader to read a midi file (specifications for the format are here)

I'm using vb.net, but I'm willing to see other code (mostly just C#, I can convert it). I'm working on a large project and this comes as a bit of a speedbump.

Here is my current code:

Private Function convertCharArrayToString(ByVal chars() As Char) As String
    Dim tReturn As String = ""
    For Each v As Char In chars
        tReturn &= v
    Next
    Return tReturn
End Function

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    midiStatus = "Reading..."
    Dim midiStream As New StreamReader(midiFile)
    Dim nBR As New BinaryReader(midiStream.BaseStream)
    midiStatus = "Validating Midi File..."
    Dim HeaderA As String = convertCharArrayToString(nBR.ReadChars(4))
    If Not HeaderA = "MThd" Then Return
    Dim HeaderB() As Byte = nBR.ReadBytes(4)
    'Get Track Type
    midiStatus = "Reading Header Data..."
    Dim TrackType1 As Integer = nBR.ReadInt16()
    Dim TrackType2 As Integer = nBR.ReadInt16()
    MsgBox(TrackType1 & TrackType2)

End Sub

Everything works find up to when I start reading the actual Header Data. I'm absoultly lost as to how I'm to continue. Any help or code examples would be nice!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞美少年 2024-11-08 03:32:27

在类中编写解码逻辑,而不是直接在 GUI 中。

为 MIDI 标头定义一个结构,然后使用类似 this 的内容来设置它。

Write your decoding logic in a class, not directly in the GUI.

Define a struct for the MIDI header, then use something like this to set it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文