環境/macOS Montery Apple Silicon Mac

番外編は下記内容にて進めていきます。
ーーーーー
Index/目次
Tidal Cycles コード例/Sound Euclidean Algorithm
Processing コード/Sound Euclidean Algorithm
ユークリッドの互除法 クラス
oscP5ライブラリーをインポートした OSCクラス

ーーーー

ーーーーー
Tidal Cycles の演奏を Processing でビジュアライズする方法 〜前編〜

Tidal Cycles の演奏を Processing でビジュアライズする方法 〜後編〜
ーーーーー

Tidal Cycles の演奏を Processing でビジュアライズする方法〜前編・後編〜を学んだ上での番外編として、OSCメッセージの “n” を利用した例です。

Tidal Cyclesの “n” は、 note の略として音源ファイルの中のwavデータをナンバリングしたものになります。d1 $ n “0 1 2 3” # sound “cpu”“n” です。

以前、Processing にて投稿した「Sound visualization / Sound Euclidean Algorithm」で紹介したコードの“ユークリッドの互除法”クラスを使っています。

また、oscのコードもoscTidalクラスとして分け、他でも使えるようにしています。

Tidal Cycles コード例/Sound Euclidean Algorithm

下記のようなTidalCyclesのコードの“n”の番号を引数として利用しています。


d1 $ n "[0 1] 0 [2 3] 2 5 4" # sound "cpu"

Processing コード/Sound Euclidean Algorithm

Processing のコードは下記から。画角は P3D にてcamera を利用しています。OPENGLもコメントアウトしています。


/**
 *Sound-Euclidean-Algo
 *This code made by barbe_generative_diary
 *URL https://barbegenerativediary.com/
 *date 4.27.2022 TidalSound-Euclidean-Algo
 */
//import processing.opengl.*;

oscTidal oscData;
euclidAlgo euclidA;

void setup() {
  size(1300,1300,P3D);
  //size(1300,1300,OPENGL);
  translate(width/2, height/2, 0); 
  camera(500, 500, 250, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0);
  background(10);
  frameRate(10);
  
    euclidA = new euclidAlgo();
  oscData = new oscTidal();
}

void draw() {
  camera(1400, 1800, 600, 
          650, 750, 0, 
          0.0, 0.0, -1.0);
  fill(10);  
  noStroke();
  rect(0, 0, width, height); 
  euclidA.update(oscData.update());
}

euclidA = new euclidAlgo();oscData = new oscTidal(); 二つのクラスをインスタンスを作成しています。

ユークリッドの互除法 クラス


/**The euclidean-Algo class
 * Drawing Euclidean-Rect
 */
class euclidAlgo{
  float margin; //margin
  float fra, initFra; //frame
  int wid;
  int amp;
  float ratio; //ratio
  float xPos,yPos;
  int itr;
  euclidAlgo(){
    margin = 300; //margin
    fra = width - margin; //frame
    initFra = fra;
    wid = 10;
    amp = 1;
    ratio = (float)amp/wid; //ratio
    xPos = 0;
    yPos = 0;
    itr = 0;
  }
  void update(int vol){
    translate(margin/2,margin/2);
    stroke(255);
    strokeWeight(2);
    smooth();
    noFill();
    wid = 10;
    amp = vol+1;
    println(wid,amp);
    ratio = (float)amp/wid;
    while(fra>0.1){
      itr++;
      if(itr%2 == 1){
        while(xPos + fra*ratio < initFra+0.1){
          divRect(xPos,yPos, fra*ratio);
          xPos += fra*ratio;
        }
        fra = initFra - xPos;
      }else{
        while(yPos + fra/ratio < initFra+0.1){
          divRect(xPos,yPos, fra);
          yPos += fra/ratio;
        }
        fra = initFra - yPos;
      }
    }
    //init
    fra = width - margin;
    xPos = 0;
    yPos = 0;
    itr = 0;
  }
  void divRect(float xPos, float yPos, float fra){
    int itrDs = 0;
    float xEndPos = xPos + fra;
    float yEndPos = yPos + fra/ratio;
    while(fra > 0.1){
      itrDs++;
      if(itrDs%2 == 0){
        while(xPos + fra < xEndPos+0.1){
          rect(xPos,yPos, fra,fra);
          xPos += fra;
        }
        fra = xEndPos - xPos;
      }else{
        while(yPos + fra < yEndPos+0.1){
          rect(xPos,yPos, fra,fra);
          yPos += fra;
        }
        fra = yEndPos - yPos;
      }
    }
    itrDs = 0;
  }
}

oscP5ライブラリーをインポートした OSCクラス


/**oscTidal class
 * Drawing Euclidean-Rect by TidalCycles
 */
 
import oscP5.*;
import netP5.*;
OscP5 osc;
int soundNum;
int noteNum = 0;
class oscTidal{
  oscTidal(){
    osc = new OscP5(this, 2020);
  }
  int update(){
    switch(noteNum) {
      case 0: soundNum = 2; break;
      case 1: soundNum = 3; break;       
      case 2: soundNum = 4; break;      
      case 3: soundNum = 5; break;
      case 4: soundNum = 6; break;
      case 5: soundNum = 7; break;       
      case 6: soundNum = 8; break;      
      case 7: soundNum = 9; break;
    }
    return soundNum;
  }
  
  void oscEvent(OscMessage m) {
    //m.print();
    for (int i = 0; i < m.typetag().length(); i+=2) {
      String name = m.get(i).stringValue();
      switch(name) {
        case "n":
        noteNum = int(m.get(i+1).floatValue());
        //sInst = m.get(i+1).stringValue();
        //println(sInst);
        break;
      }
    }
  }
}

ーーーーー
TidalCyclesから送られてくるOSCメッセージは最低限のデフォルトのものから、エフェクトなどを追加するとその数値などいろいろあります。OSCをクラスにて分け、別で制作したProcessingコードにも利用できるようにしています。
ーーーーー

barbe_generative_library

サウンドプロダクション入門 DAWの基礎と実践

SoundProduction_DTM-header

初版/ 2021.3.23
ページ数/208ページ
出版社/ビー・エヌ・エヌ
言語/日本語

【Amazon.co.jp で購入】

ーーーーー
”Books”では、”barbe_generative_Library”として、
barbe_generative_diary の創作において実際に購入し、読んだ本を紹介します。

ーーーーー

Recommend - Sounds and Movies

Try Apple Music