<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>digital matter &#187; MIDI</title>
	<atom:link href="http://blog.loadlimits.info/tag/midi/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.loadlimits.info</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 06 Feb 2012 13:27:58 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>PythonでMIDI出力をしてみる</title>
		<link>http://blog.loadlimits.info/2009/10/python%e3%81%a7midi%e5%87%ba%e5%8a%9b%e3%82%92%e3%81%97%e3%81%a6%e3%81%bf%e3%82%8b/</link>
		<comments>http://blog.loadlimits.info/2009/10/python%e3%81%a7midi%e5%87%ba%e5%8a%9b%e3%82%92%e3%81%97%e3%81%a6%e3%81%bf%e3%82%8b/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 03:15:53 +0000</pubDate>
		<dc:creator>hotpi</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[解決]]></category>
		<category><![CDATA[MIDI]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://blog.loadlimits.info/2009/10/python%e3%81%a7midi%e5%87%ba%e5%8a%9b%e3%82%92%e3%81%97%e3%81%a6%e3%81%bf%e3%82%8b/</guid>
		<description><![CDATA[既存のPythonで作ったWindowsアプリケーションにMIDI出力を組み込む用事があったので、実験してみました。 参考サイトはこちら。 sulume blog» ブログアーカイブ » python で MIDI を使う MIDIIO.dllというのはおーぷんMIDIぷろじぇくとで公開されているMIDIメッセージ入出力用ライブラリです。 これもダウンロードして、pyファイルと同じ場所に置いておきます。 で、ソースコードはこちら。 import ctypes import time midiiolib = ctypes.windll.LoadLibrary(r".\MIDIIO.dll") c_deviceName = ctypes.create_string_buffer(32) midiiolib.MIDIOut_GetDeviceName(0, c_deviceName, 32) midiout = midiiolib.MIDIOut_Open(c_deviceName.value) c_mess = ctypes.create_string_buffer(3) c_mess.value = '\x90\x3C\x64' midiiolib.MIDIOut_PutMIDIMessage(midiout, c_mess.value, 3) time.sleep(3) midiiolib.MIDIOut_Close(midiout) 説明することもあまりないですが、8行目のMIDIOut_GetDeviceNameで、MIDI出力の先頭のデバイスの名前を先に取得します。 で、その名前を使ってMIDIOut_Openで出力デバイスを開きます。 11～12行目ではノートを作成します。とりあえずドの音でも鳴らしておきます。この辺もMIDIIO.dllに入っていたドキュメントのサンプルと同じ。 あとはMIDIOut_PutMIDIMessageで出力するだけです。 ちゃんと閉じておかないと、次回音が鳴らなかったりする（オープンに失敗します）ので、MIDIOut_Closeで閉じておきましょう。 実験として、ちょっと長いデータを指定してみる。 import ctypes import time midiiolib = ctypes.windll.LoadLibrary(r".\MIDIIO.dll") c_deviceName = [...]]]></description>
			<content:encoded><![CDATA[<p>既存のPythonで作ったWindowsアプリケーションにMIDI出力を組み込む用事があったので、実験してみました。</p>
<p>参考サイトはこちら。</p>
<p><a href="http://sulume.com/blog/2009/09/26/midi-for-python/" target="_blank">sulume blog» ブログアーカイブ » python で MIDI を使う</a></p>
<p>MIDIIO.dllというのは<a href="http://openmidiproject.sourceforge.jp/" target="_blank">おーぷんMIDIぷろじぇくと</a>で公開されているMIDIメッセージ入出力用ライブラリです。</p>
<p>これもダウンロードして、pyファイルと同じ場所に置いておきます。</p>
<p>で、ソースコードはこちら。</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:2fa1f3e8-7c3e-41fb-a2b6-dd8d92243198" class="wlWriterEditableSmartContent">
<pre name="code" class="py">import ctypes
import time

midiiolib = ctypes.windll.LoadLibrary(r".\MIDIIO.dll")

c_deviceName = ctypes.create_string_buffer(32)

midiiolib.MIDIOut_GetDeviceName(0, c_deviceName, 32)
midiout = midiiolib.MIDIOut_Open(c_deviceName.value)

c_mess = ctypes.create_string_buffer(3)
c_mess.value = '\x90\x3C\x64'

midiiolib.MIDIOut_PutMIDIMessage(midiout, c_mess.value, 3)

time.sleep(3)

midiiolib.MIDIOut_Close(midiout)
</pre>
</div>
<p>説明することもあまりないですが、8行目のMIDIOut_GetDeviceNameで、MIDI出力の先頭のデバイスの名前を先に取得します。</p>
<p>で、その名前を使ってMIDIOut_Openで出力デバイスを開きます。</p>
<p>11～12行目ではノートを作成します。とりあえずドの音でも鳴らしておきます。この辺もMIDIIO.dllに入っていたドキュメントのサンプルと同じ。</p>
<p>あとはMIDIOut_PutMIDIMessageで出力するだけです。</p>
<p>ちゃんと閉じておかないと、次回音が鳴らなかったりする（オープンに失敗します）ので、MIDIOut_Closeで閉じておきましょう。</p>
<p>実験として、ちょっと長いデータを指定してみる。</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:15aded9d-7788-453b-bed8-2cb716e5ff49" class="wlWriterEditableSmartContent">
<pre name="code" class="py">import ctypes
import time

midiiolib = ctypes.windll.LoadLibrary(r".\MIDIIO.dll")

c_deviceName = ctypes.create_string_buffer(32)

midiiolib.MIDIOut_GetDeviceName(0, c_deviceName, 32)
midiout = midiiolib.MIDIOut_Open(c_deviceName.value)

notes = ['\x90\x3C\x64',
         '\x90\x3E\x64',
         '\x90\x40\x64',
         '\x90\x41\x64',
         '\x90\x43\x64',
         '\x90\x45\x64',
         '\x90\x47\x64',
         '\x90\x48\x64']

c_mess = ctypes.create_string_buffer(3)

for note in notes:
    c_mess.value = note

    midiiolib.MIDIOut_PutMIDIMessage(midiout, c_mess.value, 3)
    time.sleep(0.5)

time.sleep(1.0)

midiiolib.MIDIOut_Close(midiout)
</pre>
</div>
<p>和音を鳴らしてみるテスト。</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:ba211cd2-3e06-4c92-b11b-773b63841952" class="wlWriterEditableSmartContent">
<pre name="code" class="py">import ctypes
import time

midiiolib = ctypes.windll.LoadLibrary(r".\MIDIIO.dll")

c_deviceName = ctypes.create_string_buffer(32)

midiiolib.MIDIOut_GetDeviceName(0, c_deviceName, 32)
midiout = midiiolib.MIDIOut_Open(c_deviceName.value)

notes = ['\x90\x3C\x64',
         '\x90\x40\x64',
         '\x90\x43\x64']

c_mess = ctypes.create_string_buffer(3)

for note in notes:
    c_mess.value = note

    midiiolib.MIDIOut_PutMIDIMessage(midiout, c_mess.value, 3)

time.sleep(3.0)

midiiolib.MIDIOut_Close(midiout)
</pre>
</div>
<p>とりあえずこれだけできれば満足なので終了。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.loadlimits.info/2009/10/python%e3%81%a7midi%e5%87%ba%e5%8a%9b%e3%82%92%e3%81%97%e3%81%a6%e3%81%bf%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

