> For the complete documentation index, see [llms.txt](https://masaki-yamabe.gitbook.io/dda2023-vie-visualization/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://masaki-yamabe.gitbook.io/dda2023-vie-visualization/wosuru.md).

# 脳波を取得する

<figure><img src="/files/2tUc5r3IZdp2aA9NHMyQ" alt=""><figcaption><p>実行画面</p></figcaption></figure>

## サンプルコード：

* 実行手順
  * Vieを装着し、Vie StreamでVieに接続
  * 「計測開始(Activate Sensor)」ボタンを押す
  * 「OSC転送(OSC Streaming)」ボタンを押す
  * 「ポート番号」と「デバイス識別子」を確認。（通常はそれぞれ、65001、1）
  * コードの実行

{% file src="/files/ACrgqIaQS2ryFOQ10ams" %}

* トラブルシュート
  * oscP5ライブラリがインストールされていない
    * \[スケッチ] > \[ライブラリインポート] > \[Manage Libraries]&#x20;
    * 開いたウインドウで 「oscP5」を検索してinstall
  * Processingのバージョンが低い
    * 最新版（4以上）を入れる

## Vie Streamerの仕様について

* アドレス (left)：`/wave/L/<devid>`

  アドレス (right)：`/wave/R/<devid>`
* フォーマット：5つの小数値が、全体の周波数に対するデルタ／シータ／アルファ／ベータ／ガンマの比較貢献度をを示す。理論的な極限値は、0%から100%。
* 例：デルタの値が38%であれば、スペクトラム内の全ての周波数のなかで、38%の周波数エネルギーが、デルタ帯域（0.5Hz to 4Hz）の中にあることを示している。

[詳しくはちらを参照](https://www.notion.so/Neuro-Music-6083ccfa38414f768b06efdf9d48f7bb?pvs=4#c8a363f60042484293375582ed3217cc)

## サンプルコードの解説

{% code lineNumbers="true" %}

```processing
//OSC関連のライブラリーをインポート
import oscP5.*;
import netP5.*;

//OSCP5クラスのインスタンス
OscP5 oscP5;

//左の脳波用配列
float [] waveLeft  = new float[5];

//右の脳波用配列
float [] waveRight = new float[5];

//各配列のindex0~4にDelta,Theta,Alpha,Beta,Gamma波の数値が入る
//waveLeft[0]:DeltaLeft  waveRight[0]:DeltaRight
//waveLeft[1]:ThetaLeft  waveRight[1]:ThetaRight
//waveLeft[2]:AlphaLeft  waveRight[2]:AlphaRight
//waveLeft[3]:BetaLeft   waveRight[3]:BetaRight
//waveLeft[4]:GammaLeft  waveRight[4]:GammaRight

//表示のための設定
String [] colorHex = {"FF034AA6", "FF72B6F2", "FF73BFB1", "FFF2A30F", "FFF26F63"};
String [] bandName = {"Delta", "Theta", "Alpha", "Beta", "Gamma"};

void setup() {
  size(800,600);
  frameRate(60);
  //ポートを65001に設定して新規にOSCP5のインスタンスを生成
  oscP5 = new OscP5(this,65001);
}

void draw() {
  background(0);
  noStroke();
  
  //waveLeftの描画
  for(int i=0;i<5;i++){
    fill(unhex(colorHex[i]));
    rect(130, 50+30*i, waveLeft[i], 20);
    fill(255);
    text(bandName[i], 30, 65+30*i);
    text(floor(waveLeft[i])+"%", waveLeft[i]+140, 65+30*i );
  }
  
  //waveRightの描画
  for(int i=0;i<5;i++){
    fill(unhex(colorHex[i]));
    rect(400, 50+30*i, waveRight[i], 20);
    fill(255);
    text(bandName[i], 300, 65+30*i);
    text(floor(waveRight[i])+"%", waveRight[i]+410, 65+30*i );
  }
  
  //ラベル
  text("Left", 30, 30);
  text("Right", 300, 30);

}

//OSCメッセージを受信した際に実行するイベント
//msg.get()の引数を0〜4に変えることで、
//送出されてくる各脳波（Delta, Theta, Alpha, Beta, Gamma）の値が取得できる。
//取得した数値を左右それぞれの配列に代入する
void oscEvent(OscMessage msg) {
  
  if(msg.checkAddrPattern("/wave/L/1")==true) {   
    for(int i=0;i<5;i++){
      waveLeft[i] = msg.get(i).floatValue();
    }    
  }
  if(msg.checkAddrPattern("/wave/R/1")==true) {   
    for(int i=0;i<5;i++){
      waveRight[i] = msg.get(i).floatValue();
    }    
  }

}
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://masaki-yamabe.gitbook.io/dda2023-vie-visualization/wosuru.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
