2015年6月3日 星期三

Processing: Play GarageBand With Virtual MIDI Cables(Ports) On Mac

since: 2015/06/03
update: 2015/06/03

reference:
1. How to use the IAC Driver - MFA Lab
2. Create virtual MIDI ports on Mac


A. Create a virtual MIDI Port:

    1. 應用程式 > 工具程式 > 音訊 MIDI 設定.app

    2. 視窗 > 顯示 MIDI 錄音室

    3. 滑鼠雙擊 IAC (Inter-application communication) 驅動程式:

    4. 勾選: 裝置已接上電腦; 新增自訂名稱的傳輸埠, 即完成.

-----------------------------------------------------------------------------------------------

B. GarageBand:

    1. 打開 GarageBand, 點選電子樂, 按下 "選擇"

    2. 檢查 "偏好設定": (預設即可)

    3. 選擇合適的演奏樂器, 檔案 > 儲存

-----------------------------------------------------------------------------------------------

C. Processing:
     1. 打開 Processing, 新增 Sketch , 並匯入 MidiBus 函式庫:

     2. 撰寫程式碼如下:
import themidibus.*; //Import the library

MidiBus myBus; // The MidiBus

int channel;
int pitch;
int velocity;

int number;
int value;

void setup() {
  size(400, 400);
  background(0);

  // List all available Midi devices on STDOUT.
  // This will show each device's index and name.

  MidiBus.list();
 
  // Create a new MidiBus with no input device and the "IAC_MIDI" as the output device.
  //myBus = new MidiBus(this, -1, 2);
  myBus = new MidiBus(this,
"IAC_MIDI", "IAC_MIDI"); // Input, Output device
 

  channel = 0;
  pitch = 64;
  velocity = 127;
 
  number = 0;
  value = 90; 
}

void draw() {

  pitch = int(random(127));
  velocity = int(random(127));

  myBus.sendNoteOn(channel, pitch, velocity); // Send a Midi noteOn
  delay(200);
  myBus.sendNoteOff(channel, pitch, velocity); // Send a Midi nodeOff
 
  myBus.sendControllerChange(channel, number, value); // Send a controllerChange
  delay(2000);
}

void noteOn(int channel, int pitch, int velocity) {
  // Receive a noteOn
  println();
  println("Note On:");
  println("--------");
  println("Channel:"+channel);
  println("Pitch:"+pitch);
  println("Velocity:"+velocity);
}

void noteOff(int channel, int pitch, int velocity) {
  // Receive a noteOff
  println();
  println("Note Off:");
  println("--------");
  println("Channel:"+channel);
  println("Pitch:"+pitch);
  println("Velocity:"+velocity);
}

void controllerChange(int channel, int number, int value) {
  // Receive a controllerChange
  println();
  println("Controller Change:");
  println("--------");
  println("Channel:"+channel);
  println("Number:"+number);
  println("Value:"+value);
}

void delay(int time) {
  int current = millis();
  while (millis () < current+time) Thread.yield();
}

     2. 執行結果:


沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。