How can I make this idea possible? (sound alphabet)

Hi. I'm 22yo design major student.

Sorry for the bad english. I might be suck to understand. I try to make some kind of interaction work that by writing some words, It becomes a short melody on processing. And you can see your typewriting like usual web environment. It don't have to be a certain word and I try to make them sound when enterkey pressed.

this is the example)

In blank space, cursor blinking. You write some short sentences. You press enterkey. It becomes little melody that matched the keycode that you pressed. Like if you write 'a little butterfly' It became 'a' note melody~ 'l' note melody~ 'i' note melody~.

I used Pfont function for the text and Minim for the sound part. However I can't make them work togher.

A little example will helps me to understand, I really appreciate.

Thanks for reading this mess.

Answers

  • show your entire code

  • @jeremy_wilde====

    guidelines:

    i suppose that you have an arraylist {"butterfly", "mosquitos", "CIA drones" && you have an another arrayList with the titles of your songs

    Arraylist {"happy whe are its springtime", "arrgh!", "god bless the queen"...

    you get the id of the one and play the same for the second "play", "getAt()"

  • Pretty sure they wanted music clips played for each letter, not every word.

  • yes It's for each letter

    It's my code for text

    PFont font; int num = 500; char a[] = new char[num]; int key_num = 0; int text_w_gap = 20; int text_h_gap = 30; int ypos = 50;
    int xpos = 10; void setup() { size(500, 400); font = loadFont("whiteday10-48.vlw"); textFont(font, 32); }

    void draw() { background(0); for (int i=0; i<key_num; i++) { text(a[i], (xpos+(itext_w_gap))%width, ypos+( (int(xpos+(itext_w_gap))) / width * text_h_gap)); } if(key_num >= num) { key_num = 0; } }

    void keyPressed() { if (key!=8) { a[key_num] = key; key_num++; } else { key_num--; } println("pressed " + int(key) + " " + keyCode); }

  • and your code for sound?

  • PFont font; 
    int num = 500; 
    char a[] = new char[num]; 
    int key_num = 0; 
    int text_w_gap = 20; 
    int text_h_gap = 30; 
    int ypos = 50;
    int xpos = 10;
    
    boolean playSong=false; 
    
    void setup() { 
      size(500, 400); 
      font = createFont("whiteday10-48.vlw", 14); 
      textFont(font, 32);
    }
    
    void draw() { 
      background(0);
    
      // ------------------
      if (playSong) { 
        for (int i=0; i<key_num; i++) {
          playNote(a[i]);
        }//for
      }//if
      else
        // ------------------
      {
        for (int i=0; i<key_num; i++) { 
          text(a[i], (xpos+(i*text_w_gap))%width, 
            ypos+( (int(xpos+(i*text_w_gap))) / width * text_h_gap));
        } 
        if (key_num >= num) { 
          key_num = 0;
        }
      }
    }// func 
    
    void keyPressed() { 
      if (key!=8) { 
        a[key_num] = key; 
        key_num++;
      } else if (key==RETURN||key==ENTER) {
        playSong=true;
      } else if (key==8) { 
        key_num--;
      } 
      println("pressed " + int(key) + " " + keyCode);
    }
    
  • thanks for the comments:) I really appreciate

    this is my sound part.

    import ddf.minim.*; import processing.serial.*;

    Minim minim; AudioPlayer c,d,e,f,g,a,b,cc;

    int val;

    void setup(){ size(200,200);

    minim = new Minim(this);

    c = minim.loadFile("c.mp3"); d = minim.loadFile("d.mp3"); e = minim.loadFile("e.mp3"); f = minim.loadFile("f.mp3"); g = minim.loadFile("g.mp3"); a = minim.loadFile("a.mp3");

    void draw(){ background(255);

    if ( myPort.available() > 0) { val = myPort.read(); }

    if(val==1){ c.play();

    if (c.position() > 600 )
    

    { c.rewind(); } } if(val==2){ d.play();

    if (dm.position() > 600 )
    

    { d.rewind(); } }

    if(val==3){ e.play();

    if (e.position() > 600 )
    

    { e.rewind(); } }

    if(val==4){ f.play();

    if (f.position() > 600 )
    

    { f.rewind(); } }

    if(val==5){ g.play();

    if (g.position() > 600 )
    

    { g.rewind(); } }

    if(val==6){ a.play();

    if (a.position() > 600 )
    

    { a.rewind(); } } if(val==7){ }

    println(val); }

    this code was for the interaction button piano with arduino.

    I try to change this code for only processing but I'm stuck in here..

  • excellent.

    Now, val is giving you the note in your code.

    So place this function into playNote() in my code.

    void playNote(char val) {
    
        // as above
    
    }
    

    some changes and it runs.....

  • thank you so much, Chrisir.

    but I still don't know where to put those code.

    I'm really sorry but

    Could you show me the example for the combined code?

    When void playNote... goes into my original text code, It doesn't work...

  • show your attempt

  • import ddf.minim.*;

    Minim minim; AudioPlayer c, d, e, f, g, a, b, cc;

    PFont font; int num = 500; char t[] = new char[num]; int key_num = 0; int text_w_gap = 20; int text_h_gap = 30; int ypos = 50; int xpos = 10; int val;

    boolean playSong=false;

    void setup() { size(500, 400); font = createFont("whiteday10-48.vlw", 14); textFont(font, 32); minim = new Minim(this);

    c = minim.loadFile("c.mp3"); d = minim.loadFile("d.mp3"); e = minim.loadFile("e.mp3"); f = minim.loadFile("f.mp3"); g = minim.loadFile("g.mp3"); a = minim.loadFile("a.mp3"); }

    void draw() { background(0);

    // ------------------ if (playSong) { for (int i=0; i<key_num; i++) { playNote(t[i]); }//for }//if else // ------------------ { for (int i=0; i<key_num; i++) { text(t[i], (xpos+(itext_w_gap))%width, ypos+( (int(xpos+(itext_w_gap))) / width * text_h_gap)); } if (key_num >= num) { key_num = 0; } } }

    void keyPressed() { if (key!=8) { t[key_num] = key; key_num++; } else if (key==RETURN||key==ENTER) { playSong=true; } else if (key==8) { key_num--; } println("pressed " + int(key) + " " + keyCode); }

    void playNote(char val) { if () { val = myPort.read(); }

    if (val==1) { c.play();

    if (c.position() > 600 )
    {
      c.rewind();
    }
    

    } if (val==2) { d.play();

    if (d.position() > 600 )
    {
      d.rewind();
    }
    

    }

    if (val==3) { e.play();

    if (e.position() > 600 )
    {
      e.rewind();
    }
    

    }

    if (val==4) { f.play();

    if (f.position() > 600 )
    {
      f.rewind();
    }
    

    }

    if (val==5) { g.play();

    if (g.position() > 600 )
    {
      g.rewind();
    }
    

    }

    if (val==6) { a.play();

    if (a.position() > 600 )
    {
      a.rewind();
    }
    

    } if (val==7) { } }

    Serial part doesn't work..

  • import ddf.minim.*;
    
    Minim minim; 
    AudioPlayer c, d, e, f, g, a, b, cc;
    
    PFont font; 
    int num = 500; 
    char t[] = new char[num]; 
    int key_num = 0; 
    int text_w_gap = 20; 
    int text_h_gap = 30; 
    int ypos = 50; 
    int xpos = 10; 
    int val;
    
    boolean playSong=false;
    
    void setup() { 
      size(500, 400); 
      font = createFont("whiteday10-48.vlw", 14); 
      textFont(font, 32); 
      minim = new Minim(this);
    
      c = minim.loadFile("c.mp3"); 
      d = minim.loadFile("d.mp3"); 
      e = minim.loadFile("e.mp3"); 
      f = minim.loadFile("f.mp3"); 
      g = minim.loadFile("g.mp3"); 
      a = minim.loadFile("a.mp3");
    }
    
    void draw() { 
      background(0);
    
      // ------------------ 
    
      if (playSong) { 
        for (int i=0; i<key_num; i++) { 
          playNote(t[i]);
        }//for
      }
      //if 
      else // ------------------ 
      { 
        for (int i=0; i<key_num; i++) { 
          text(t[i], 
            (xpos+(i*text_w_gap))%width, 
            ypos+( (int(xpos+(i*text_w_gap))) / width * text_h_gap));
        } 
        if (key_num >= num) { 
          key_num = 0;
        }
      }
    }
    
    void keyPressed() { 
      if (key!=8) { 
        t[key_num] = key; 
        key_num++;
      } else if (key==RETURN||key==ENTER) { 
        playSong=true;
      } else if (key==8) { 
        key_num--;
      } 
      println("pressed " + int(key) + " " + keyCode);
    }
    
    void playNote(char val) { 
      if (val=='a') { 
        c.play();
        if (c.position() > 600 )
        {
          c.rewind();
        }
      } 
      if (val=='b') { 
        d.play();
        if (d.position() > 600 )
        {
          d.rewind();
        }
      }
      if (val=='c') { 
        e.play();
        if (e.position() > 600 )
        {
          e.rewind();
        }
      }
      if (val=='d') { 
        f.play();
        if (f.position() > 600 )
        {
          f.rewind();
        }
      }
      if (val=='e') { 
        g.play();
        if (g.position() > 600 )
        {
          g.rewind();
        }
      }
    
      if (val=='f') { 
        a.play();
        if (a.position() > 600 )
        {
          a.rewind();
        }
      } 
      if (val=='g') {
      }
    }
    //
    
  • import ddf.minim.*;
    
    Minim minim;
    AudioPlayer c, d, e, f, g, a, b, cc;
    
    PFont font; 
    int num = 500; 
    char t[] = new char[num]; 
    int key_num = 0; 
    int text_w_gap = 20; 
    int text_h_gap = 30; 
    int ypos = 50;
    int xpos = 10;
    int val;
    
    boolean playSong=false; 
    
    void setup() { 
      size(500, 400); 
      font = createFont("whiteday10-48.vlw", 14); 
      textFont(font, 32);
      minim = new Minim(this);
    
      c = minim.loadFile("c.mp3");
      d = minim.loadFile("d.mp3");
      e = minim.loadFile("e.mp3");
      f = minim.loadFile("f.mp3");
      g = minim.loadFile("g.mp3");
      a = minim.loadFile("a.mp3");
    }
    
    void draw() { 
      background(0);
    
      // ------------------
      if (playSong) { 
        for (int i=0; i<key_num; i++) {
          playNote(t[i]);
        }//for
      }//if
      else
        // ------------------
      {
        for (int i=0; i<key_num; i++) { 
          text(t[i], (xpos+(i*text_w_gap))%width, 
            ypos+( (int(xpos+(i*text_w_gap))) / width * text_h_gap));
        } 
        if (key_num >= num) { 
          key_num = 0;
        }
      }
    }
    
    void keyPressed() { 
      if (key!=8) { 
        t[key_num] = key; 
        key_num++;
      } else if (key==RETURN||key==ENTER) {
        playSong=true;
      } else if (key==8) { 
        key_num--;
      } 
      println("pressed " + int(key) + " " + keyCode);
    }
    
    void playNote(char val) {
      if () {
        val = myPort.read();
      }
    
    
      if (val==1) {
        c.play();
    
        if (c.position() > 600 )
        {
          c.rewind();
        }
      }
      if (val==2) {
        d.play();
    
        if (d.position() > 600 )
        {
          d.rewind();
        }
      }
    
      if (val==3) {
        e.play();
    
        if (e.position() > 600 )
        {
          e.rewind();
        }
      }
    
      if (val==4) {
        f.play();
    
        if (f.position() > 600 )
        {
          f.rewind();
        }
      }
    
      if (val==5) {
        g.play();
    
        if (g.position() > 600 )
        {
          g.rewind();
        }
      }
    
      if (val==6) {
        a.play();
    
        if (a.position() > 600 )
        {
          a.rewind();
        }
      }
      if (val==7) {
      }
    }
    
  • ok you don't need serial because we reading from keybd

    this is wrong if (val==1) { c.play();

    since we're passing chars to the function

    try if (val=='a') { c.play();

    I did that

  • ok, read my comment

    I gotta go

  • Thank you so much Chrisir.

    I'll try that way! :)

  • Answer ✓

    The discussion has moved to here

    In future do not split the same question over 2 discussions.

This discussion has been closed.