掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
MIDIを使用する(VB.Net) (ID:86381)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
わこです。 今回、 「MIDIを使用して音を出す」 という作業をしています。 Textboxにドと入力してボタンを押すと ドの音が鳴るというものです。。。 下記までできましたが、 そのあとから進まなくなりまして みなさまの力を借りようと ここで質問させていただきました。 だれか、ご教授おねがいいたします。 Option Strict Off Option Explicit On Friend Class Form1 Inherits System.Windows.Forms.Form #Region " Windows フォーム デザイナで生成されたコード " Public Sub New() MyBase.New() ' この呼び出しは Windows フォーム デザイナで必要です。 InitializeComponent() ' InitializeComponent() 呼び出しの後に初期化を追加します。 End Sub ' Form は、コンポーネント一覧に後処理を実行するために dispose をオーバーライドします。 Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub ' Windows フォーム デザイナで必要です。 Private components As System.ComponentModel.IContainer ' メモ : 以下のプロシージャは、Windows フォーム デザイナで必要です。 'Windows フォーム デザイナを使って変更してください。 ' コード エディタを使って変更しないでください。 Friend WithEvents TextBox1 As System.Windows.Forms.TextBox Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents Timer1 As System.Windows.Forms.Timer <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.components = New System.ComponentModel.Container Me.TextBox1 = New System.Windows.Forms.TextBox Me.Button1 = New System.Windows.Forms.Button Me.Timer1 = New System.Windows.Forms.Timer(Me.components) Me.SuspendLayout() ' 'TextBox1 ' Me.TextBox1.Location = New System.Drawing.Point(40, 32) Me.TextBox1.Name = "TextBox1" Me.TextBox1.Size = New System.Drawing.Size(208, 19) Me.TextBox1.TabIndex = 0 Me.TextBox1.Text = "音階を書き込んでください" ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(40, 80) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(208, 152) Me.Button1.TabIndex = 1 Me.Button1.Text = "音を鳴らす" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12) Me.ClientSize = New System.Drawing.Size(292, 266) Me.Controls.Add(Me.Button1) Me.Controls.Add(Me.TextBox1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region Private Declare Function midiOutOpen Lib "winmm.dll" (ByRef lphMidiOut As Integer, ByVal uDeviceID As Integer, ByVal dwCallback As Integer, ByVal dwInstance As Integer, ByVal dwFlags As Integer) As Integer Private Declare Function midiOutShortMsg Lib "winmm.dll" (ByVal hMidiOut As Integer, ByVal dwMsg As Integer) As Integer Private Declare Function midiOutClose Lib "winmm.dll" (ByVal hMidiOut As Integer) As Integer Dim hMid As Object Dim Note As Integer Dim r As Integer Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load 'MIDIデバイスのオープン 'UPGRADE_WARNING: オブジェクト hMid の既定プロパティを解決できませんでした。 詳細については次のリンクをクリックしてください : 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"' If midiOutOpen(hMid, -1, 0, 0, 0) <> 0 Then MsgBox("MIDIデバイスオープンに失敗しました") End If End Sub 'UPGRADE_WARNING: Form イベント Form1.QueryUnload には新しい動作が含まれます。 詳細については次のリンクをクリックしてください : 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup2065"' Private Sub Form1_Closing(ByVal eventSender As System.Object, ByVal eventArgs As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing Dim Cancel As Short = eventArgs.Cancel 'MIDIデバイスのクローズ 'UPGRADE_WARNING: オブジェクト hMid の既定プロパティを解決できませんでした。 詳細については次のリンクをクリックしてください : 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"' midiOutClose(hMid) eventArgs.Cancel = Cancel End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Inst As Object Dim Vol As Integer Timer1.Enabled = True Timer1.Interval = 300 Note = 70 '音階(&H00から&H7F(127)) 'UPGRADE_WARNING: オブジェクト Inst の既定プロパティを解決できませんでした。 詳細については次のリンクをクリックしてください : 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"' Inst = 30 '楽器No(GM音色番号に準拠?) Vol = &H7FS '音量(&H00から&H7F(127)) '楽器の変更(1バイト目:データの種類&チャンネル番号 ' 2バイト目:音色番号) 'UPGRADE_WARNING: オブジェクト Inst の既定プロパティを解決できませんでした。 詳細については次のリンクをクリックしてください : 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"' 'UPGRADE_WARNING: オブジェクト hMid の既定プロパティを解決できませんでした。 詳細については次のリンクをクリックしてください : 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"' midiOutShortMsg(hMid, &HC0S + Inst * 256) '音を鳴らす(1バイト目:データの種類&チャンネル番号 ' 2バイト目:音階 ' 3バイト目:ボリューム) 'UPGRADE_WARNING: オブジェクト hMid の既定プロパティを解決できませんでした。 詳細については次のリンクをクリックしてください : 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"' midiOutShortMsg(hMid, &H90S + Note * 256 + Vol * 256 * 256) End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick If r = 5 Then midiOutShortMsg(hMid, &H80S + Note * 256) r = 0 End If r = r + 1 End Sub '入力されたキーをMIDIの音符に変換する Function mididata(ByRef KeyCode As Short) As Integer Dim a As Integer Select Case KeyCode Case 90 'a a = &H39S Case 83 'a# a = &H3AS Case 88 'b a = &H3BS Case 67 'c a = &H3CS Case 70 'c# a = &H3DS Case 86 'd a = &H3ES Case 71 'd# a = &H3FS Case 66 'e a = &H40S Case 78 'f a = &H41S Case 74 'f# a = &H42S Case 77 'g a = &H43S Case 75 'g# a = &H44S Case 188 'a a = &H45S Case 76 'a# a = &H46S Case 190 'b a = &H47S Case 191 'c a = &H48S Case 186 'c# a = &H49S Case 226 'd a = &H4AS Case 221 'd# a = &H4BS Case Else a = 0 End Select mididata = a End Function End Class
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.