オラのバージョンはArduinoの1.0.1。
コンパイルも通った。
しかし、Gertduinoでの導入は無理だった。
ArduinoUNOのUSBがどこまで関わっているのか不明。
Gertduinoでは制限が多いみたいだ。
シリアル通信自体、お恥ずかしながら、ブラックボックスなので、どこでどうやればいいか困っている。
このライブラリの内容を見て、信号解析に役立てれればいいと思った。
そんなに難しいことはやっていないと思うんだけど。
通信の規約さえ、つかめれば、音は制御可能なように思う。
音が実際に出ているんだから、あとは、その信号が分かればいいだけ。
通信には定義があるので、通らないわけがない。
あ、それから、ギター巻弦のこと。
一日一本通すって言ったけど、暑くて無理。
たった30分が我慢できない。
Gertduino始めてから、物事が前に進まなくなった。
今週中に出来なかったら、Pythonの方、移ったほうが良さそうだ。
成長の伸びしろが大きいんで、やりがいはありそう。
って、若いSEのブログなんか見てたら学習能力半端じゃないから、オラって奴はダメだなあってつくづく思う。
LPIC試験対策の勉強なんか始めるころには、もう、ついてけないブログになっている。
LPIC持ってたら、Linux使えるって言ってもいいくらいかな。
オラは、中途半端。
悔しいけど発達していない。
なんでかなあ。
マイコンにしたって、パソ通とかMIDIとか、電子回路設計についてだとか、知らないものなあ。
何やっても半端なんだ。
でも、全体を客観的に見渡すくらいの技量はあるかなあ。
■Ardumidi.h■
// file version 0.60
#ifndef ardumidi_h
#define ardumidi_h
#include "Arduino.h"
// MIDI notes
#define MIDI_C0 0
#define MIDI_D0 2
#define MIDI_E0 4
#define MIDI_F0 5
#define MIDI_G0 7
#define MIDI_A0 9
#define MIDI_B0 11
#define MIDI_C 60
#define MIDI_D 62
#define MIDI_E 64
#define MIDI_F 65
#define MIDI_G 67
#define MIDI_A 69
#define MIDI_B 71
#define MIDI_SHARP 1
#define MIDI_FLAT -1
#define MIDI_OCTAVE 12
// MIDI out
#define MIDI_NOTE_OFF 0x80
#define MIDI_NOTE_ON 0x90
#define MIDI_PRESSURE 0xA0
#define MIDI_CONTROLLER_CHANGE 0xB0
#define MIDI_PROGRAM_CHANGE 0xC0
#define MIDI_CHANNEL_PRESSURE 0xD0
#define MIDI_PITCH_BEND 0xE0
struct MidiMessage {
byte command;
byte channel;
byte param1;
byte param2;
};
// MIDI in
void midi_note_off(byte channel, byte key, byte velocity);
void midi_note_on(byte channel, byte key, byte velocity);
void midi_key_pressure(byte channel, byte key, byte value);
void midi_controller_change(byte channel, byte control, byte value);
void midi_program_change(byte channel, byte program);
void midi_channel_pressure(byte channel, byte value);
void midi_pitch_bend(byte channel, int value);
void midi_command(byte command, byte channel, byte param1, byte param2);
void midi_command_short(byte command, byte channel, byte param1);
// MIDI out
int midi_message_available();
MidiMessage read_midi_message();
int get_pitch_bend(MidiMessage msg);
// Other
void midi_print(char* msg, int len);
void midi_comment(char* msg);
#endif
■Ardumidi.cpp■
// file version 0.60
#include "Arduino.h"
#include "HardwareSerial.h"
#include "ardumidi.h"
void midi_note_off(byte channel, byte key, byte velocity)
{
midi_command(0x80, channel, key, velocity);
}
void midi_note_on(byte channel, byte key, byte velocity)
{
midi_command(0x90, channel, key, velocity);
}
void midi_key_pressure(byte channel, byte key, byte value)
{
midi_command(0xA0, channel, key, value);
}
void midi_controller_change(byte channel, byte control, byte value)
{
midi_command(0xB0, channel, control, value);
}
void midi_program_change(byte channel, byte program)
{
midi_command_short(0xC0, channel, program);
}
void midi_channel_pressure(byte channel, byte value)
{
midi_command_short(0xD0, channel, value);
}
void midi_pitch_bend(byte channel, int value)
{
midi_command(0xE0, channel, value & 0x7F, value >> 7);
}
void midi_command(byte command, byte channel, byte param1, byte param2)
{
Serial.write(command | (channel & 0x0F));
Serial.write(param1 & 0x7F);
Serial.write(param2 & 0x7F);
}
void midi_command_short(byte command, byte channel, byte param1)
{
Serial.write(command | (channel & 0x0F));
Serial.write(param1 & 0x7F);
}
void midi_print(char* msg, int len)
{
Serial.write(0xFF);
Serial.print(0x00);
Serial.print(0x00);
Serial.write(len);
Serial.print(msg);
}
void midi_comment(char* msg)
{
int len = 0;
char* ptr = msg;
while (*ptr++) len++;
midi_print(msg, len);
}
int midi_message_available() {
/*
This bit will check that next bytes to be read would actually
have the midi status bit. If not it will remove uncorrect bytes
from internal buffer
*/
while ((Serial.available() > 0) && ((Serial.peek() & B10000000) != 0x80)) {
Serial.read();
}
/* Well we don't exactly know how many commands there might be in the Serial buffer
so we'll just guess it according the type of message that happens to be waiting
in the buffer. At least we get first one right! */
byte command = Serial.peek() & 11110000;
if (command != MIDI_PROGRAM_CHANGE && command != MIDI_CHANNEL_PRESSURE) {
return (Serial.available()/2);
}
return (Serial.available()/3);
}
MidiMessage read_midi_message() {
MidiMessage message;
byte midi_status = Serial.read();
message.command = (midi_status & B11110000);
message.channel = (midi_status & B00001111);
message.param1 = Serial.read();
if (message.command != MIDI_PROGRAM_CHANGE && message.command != MIDI_CHANNEL_PRESSURE) {
message.param2 = Serial.read();
}
return message;
}
int get_pitch_bend(MidiMessage m) {
return (m.param1 & 0x7F) + ((m.param2 & 0x7F) << 7);
}