Text String Array to Midi sound help a noob
in
Contributed Library Questions
•
2 years ago
Trying to set a text chain to midi music with an associated visual.
Well I've gotten this code to this stage it is not elegent but it is doing what I want it to do. My problem is that I want a visual going along with the notes and code. I wanted to map the value of "note" to between 0 and the width and display a rectangle at the coordinate that corresponds with the value of the note that is being played.
The problem is this: I guess when it goes through the for loop in the printStringToInts function draw doesn't run until the loop is completed and then only for one frame. I can get the rectangles to draw all at once inside the for loop but I want them to go off individually as a animation where they are ping ponging around the screen. Please help if you can I'd really appreciate I can't figure it out...
Here is the code:
import themidibus.*;
MidiBus myBus;
String[] headlines = {
"Communication: 07.06.2011",
"Jesse (1:25 AM): Made it home fine. Still pissed at the douche tho. Hope when your the bartender you don’t get butt hurt when I flip you off.",
"Tierna (9:05 AM): Can you meet @ 330?",
"Jason (9:37 AM): Don’t live like it’s your last day. That’s dumb. You’d be like, crying. Make today awesome and live like it’s today.",
"@Jesse (10:00 AM): Hey just got yr text glad you made it safe and don’t worry about my coworker he’s sensitive",
"@Tierna (10:01 AM): Yeah that should be fine I just have to be at work by five in rio rancho.",
"@Jason (10:03 AM): Sage words",
"Tierna (10:05 AM): K it will take about 20 min" ,
"@Tierna(10:06 AM): Sounds good flying star at three thirty see you then" ,
"Unknown(10:09 AM): Boo!",
"@Unknown(10:12 AM): You scared me. Who are you?" ,
"Unknown(10:13 AM): The Plumber" ,
"@Unknown(10:14 AM): Jake Plumber? What’s up man!" ,
"Unknown(10:16 AM): No…the plumber…I’ve come to fix your sink" ,
"@Unknown(10:18 AM): Oh OK well the key is under the door mat and I put a check on the table for you. Seriously who is this though?" ,
"Unknown(10:21 AM): It’s Chrissy goof!" ,
"@Unknown(10:23 AM): Haha. Oh hey what is up? I’m in summer school class right now" ,
"Unknown(10:25 AM): LOL summer school?" ,
"Sonya(10:26 AM): Have a good day in class!" ,
"@Sonya(10:28 AM): K call you when I get out xoxo" ,
"Unknown(1:45 PM): OMG I’m so sorry I was texting the wrong number lol" ,
"@Unknown(1:50 PM): Haha no worries. Thanks for fixing the sink" ,
"Unknown(1:53 PM): LOL sorry!" ,
"Taylor(2:09 PM): So I heard a band called Agent Ribbons. It was a pretty good girl band. Also check out Aerial M. They have a good 2 track ep." ,
"@Taylor(2:11 PM): Cool will do. I’ve been listening to this guy named Bob Dylan. It’s just him with an acoustic and a harmonica. It’s so awesome but his voice is a little different. You have to listen to the words man the words." ,
"Taylor(2:13 PM): Nice. I will give it a go. Is he that “everybody must get stoned guy”?" ,
"@Taylor(2:14 PM): Yeah I think that’s him. He does like a jimi Hendrix cover of All Along the Watchtower too." ,
"Taylor(2:15 PM): Oh I know that guy. I might try it. Not really my thing. U know im n2 hardcore ganster rap right?" ,
"Taylor(2:16 PM): Wanna play a quick name game? Patterson, hunter, maybin, Gomez, smoak. I really need sb’s but smoak may have a power comeback which I’ll also take." ,
"@Taylor(2:18 PM): Hmm I think I like smoak or hunter out of that group but not a lot of sbs. Not too sure what’s on the wire for speed. Hunter steals some like two a month or he used to anyways." ,
"Taylor(2:20 PM): How bout maybins gr8 walk against the mariners? Nice." ,
"@Taylor(2:22 PM): Ya that’s awesome. Intentionally walk a padre hitting .230 and choke throw it into the stands haha." ,
"Taylor(2:23 PM): Baseball is hard." ,
"@Taylor(2:24 PM): It really is. I’m so frustrated with that league." ,
"Taylor(2:26 PM): I know man. U r in an intense grind man. Circumstances will shift 2 ur favor at some point. Reading extra 2% right now I’ll loan it to you when I’m done." ,
"@Taylor(2:27 PM): Oh cool how is it? I’ll trade you Moneyball for that book and Bautista." ,
"Taylor(2:28 PM): That’s probably fair. Deal. It’s actually really good. Feel like I should have read Moneyball first but it was a dad’s day gift. Didn’t know your Sox were almost the Tampa Bay White Sox.",
"@Taylor(2:30 PM): What the fuck is that true? That would have fucking sucked",
"Taylor(2:31 PM): Apparently so ok will hit you up later bro.",
"@Sonya(3:07 PM): Hi baby. Killing time at fstar how are you?",
"Sonya(3:09 PM): I’m fine. I wish I could meet you at Flying Star :) how’s the project coming?",
"@Sonya(3:11 PM): So far so good just collecting data. I had a random person hit me up and had a little wrong number chain with them. I kept being like who is this? And they thought I was their friend so they kept texting me thinking I was joking.",
"Sonya(3:12 PM): LOL",
"Sonya(3:14 PM): Walkmen in Phoenix on Sept 15 with Fleet Foxes and Bon iver. Road Trip?",
"@Sonya(3:15 PM): Oh man. K I’m down!",
"Taylor(3:14 PM): And dude, u totally had Ogando pegged. I doubted u for dropping him, but now…",
"@Taylor(3:16 PM): Got that one right. His FIP was all fucked up.",
"Taylor(3:18 PM): Gr8 job dork!",
"Sonya(4:17 PM): What size shoe do you wear?",
"@Sonya(4:18 PM): Thirteen. Twelve in Converse.",
"Sonya(4:20 PM): That soccer players name is Hope Solo.",
"@Sonya(4:22 PM): That’s a stage name",
"@August(5:59 PM): Yr grandyman smack haha",
"August(6:01 PM): Thanks bro :) Glad someone got it…",
"Matthew(6:04 PM): I watched “White Fang” today. Did you?",
"@Matthew(6:10 PM): No but I watched a different Ethan Hawke joint. “Explorers”. River Phoenix is in it.",
"@August(6:30 PM): We might go see Walkmen and Fleet Foxes in Phoenix.",
"August(6:31 PM): Oh cool. Same show?",
"@August(6:33 PM): Yeah. Bon Iver is opening I think too.",
"August(6:35 PM): No way. He has the number one record. He’s not an opening act.",
"@August(6:36 PM): Hmm well the other two are fairly big acts so I don’t know then.",
"August(6:37 PM): Maybe. That sounds killer dude. I’m jealous.",
"@August(6:38 PM): Pixies in Santa Fe though! Hells Bells Tour.",
"August(6:39 PM): I just got a little wet.",
"@August(6:40 PM): lmfao",
"Edward(7:24 PM): Hey Vinnie! Matt saw White Fang today!",
"August(7:25 PM): Freakin lame. Sanchez blew me up again…",
"@August(7:27 PM): Romero epic digger. Bad week for me again. :(",
"@August(7:30 PM): Adam throws Masterson against the Yanks and he is freaking dealing. This season has been mentally exhausting dude.",
"Taylor(7:34 PM): You get my enviromentalist poster text?",
"@Taylor(7:36 PM): Oh yeah I did good shit. Meant to hit you up on that.",
"August(8:06 PM): Staci just told me that I’m ruining her life because I don’t want to take her on a vacation that costs $2500. She’s worried about her future…",
"@August(8:08 PM): ? What is that shit about?",
"August(8:09 PM): She says she needs to get out and experience life. And I don’t have those desires so it makes her scared about our future. And that her friends make way less than we do and they all go on vacations…",
"@August(8:11 PM): Well maybe if she got a job that would get her out of the house and experiencing life and understanding the value of money a bit better",
"August(8:12 PM): I agree. We live paycheck to paycheck. Sorry that stresses me out… That 07 VW isn’t paying for iself and neither will the house I’m trying to buy for us. And I’m ruining her existence.",
"@August(8:14 PM): That’s a bunch of horseshit",
"August(8:16 PM): I sort of get why people don’t like to come home from work now…",
"@August(8:17 PM): That’s so unfair to you it really makes me mad",
"August(8:20 PM): I thinks she’s stressed about the kids which is fine but don’t take that out on me like I don’t try and give you what you want and need.",
"Taylor(8:56 PM): My granddad just died.",
"@Taylor(8:57 PM): Oh t I am so truly sorry to hear that man.",
"@August(9:00 PM): Taylor’s grandpa passed away…RIP",
"August(9:01 PM): …Oh bummer…",
"August(9:02 PM): RIP indeed.",
"Brandon(10:13 PM): We found flights to St. Thomas next year for our wedding @ $700 round trip. Pretty cheap, may also get another discount due to group rate depending on how many people can commit now.",
"Brandon(10:15 PM): I know moneys tight, if you guys want to come let me know and I’ll include info in an email…",
};
int index;
int shade=0;
int sat=0;
int bright=0;
void setup() {
size(1024, 768);
textFont(createFont( "Arial", 14, true));
textAlign(CENTER);
rectMode(CENTER);
colorMode(HSB,360,100,100,100);
MidiBus.list();
myBus = new MidiBus(this, -1, "Java Sound Synthesizer");
}
void draw() {
background(0);
printStringToInts(headlines[index]);
colorChange();
fill(shade,sat,bright);
text(headlines[index], width/2, height-200, width/2, 100);
}
// input a string, to be printed as ints to the console
void printStringToInts(String s) {
//declare variables
int note;
int totalChar;
int t=0;
// for the length of the String
for (int i=0; i<s.length(); i++) {
// convert each character in the string to an int
// and print it to the console
note=(int)s.charAt(i);
totalChar=(int)s.length();
println((note)+","+(t)+","+(totalChar)+","+(index));
int channel = 12;
int pitch = note;
int velocity = 127;
myBus.sendNoteOn(channel, note, velocity);
int number = 0;
int value = 90;
myBus.sendControllerChange(channel, number, value);
delay(totalChar/2);
t=t+1;
if (t >= s.length()) {
t=0;
index = (index + 1) % (headlines.length);
}
}
}
//change the color based on who is texting
void colorChange(){
if (index == 1){
shade=300;
sat=53;
bright=99;
}
else if(index==2 || index==7){
shade=124;
sat=99;
bright=99;
}
else if(index==3){
shade=58;
sat=100;
bright=54;
}
else if(index==9||index==11||index==13||index==15||index==17||index==20||index==22){
shade=91;
sat=43;
bright=99;
}
else if(index==18||index==40||index==42||index==43||index==50){
shade=180;
sat=100;
bright=100;
}
else if(index==23||index==25||index==27||index==28||index==30||index==32||index==34||index==36||index==38||index==45||index==47||index==69||index==80){
shade=5;
sat=99;
bright=99;
}
else if(index==53||index==57||index==59||index==61||index==63||index==66||index==71||index==73||index==75||index==77||index==79||index==83||index==84){
shade=229;
sat=91;
bright=100;
}else if(index==54){
shade=318;
sat=24;
bright=76;
}
else if(index==65){
shade=180;
sat=1;
bright=40;
}
else if(index==85||index==86){
shade=174;
sat=34;
bright=99;
}
else{
shade=0;
sat=0;
bright=100;
}
}
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);
}
Well I've gotten this code to this stage it is not elegent but it is doing what I want it to do. My problem is that I want a visual going along with the notes and code. I wanted to map the value of "note" to between 0 and the width and display a rectangle at the coordinate that corresponds with the value of the note that is being played.
The problem is this: I guess when it goes through the for loop in the printStringToInts function draw doesn't run until the loop is completed and then only for one frame. I can get the rectangles to draw all at once inside the for loop but I want them to go off individually as a animation where they are ping ponging around the screen. Please help if you can I'd really appreciate I can't figure it out...
Here is the code:
import themidibus.*;
MidiBus myBus;
String[] headlines = {
"Communication: 07.06.2011",
"Jesse (1:25 AM): Made it home fine. Still pissed at the douche tho. Hope when your the bartender you don’t get butt hurt when I flip you off.",
"Tierna (9:05 AM): Can you meet @ 330?",
"Jason (9:37 AM): Don’t live like it’s your last day. That’s dumb. You’d be like, crying. Make today awesome and live like it’s today.",
"@Jesse (10:00 AM): Hey just got yr text glad you made it safe and don’t worry about my coworker he’s sensitive",
"@Tierna (10:01 AM): Yeah that should be fine I just have to be at work by five in rio rancho.",
"@Jason (10:03 AM): Sage words",
"Tierna (10:05 AM): K it will take about 20 min" ,
"@Tierna(10:06 AM): Sounds good flying star at three thirty see you then" ,
"Unknown(10:09 AM): Boo!",
"@Unknown(10:12 AM): You scared me. Who are you?" ,
"Unknown(10:13 AM): The Plumber" ,
"@Unknown(10:14 AM): Jake Plumber? What’s up man!" ,
"Unknown(10:16 AM): No…the plumber…I’ve come to fix your sink" ,
"@Unknown(10:18 AM): Oh OK well the key is under the door mat and I put a check on the table for you. Seriously who is this though?" ,
"Unknown(10:21 AM): It’s Chrissy goof!" ,
"@Unknown(10:23 AM): Haha. Oh hey what is up? I’m in summer school class right now" ,
"Unknown(10:25 AM): LOL summer school?" ,
"Sonya(10:26 AM): Have a good day in class!" ,
"@Sonya(10:28 AM): K call you when I get out xoxo" ,
"Unknown(1:45 PM): OMG I’m so sorry I was texting the wrong number lol" ,
"@Unknown(1:50 PM): Haha no worries. Thanks for fixing the sink" ,
"Unknown(1:53 PM): LOL sorry!" ,
"Taylor(2:09 PM): So I heard a band called Agent Ribbons. It was a pretty good girl band. Also check out Aerial M. They have a good 2 track ep." ,
"@Taylor(2:11 PM): Cool will do. I’ve been listening to this guy named Bob Dylan. It’s just him with an acoustic and a harmonica. It’s so awesome but his voice is a little different. You have to listen to the words man the words." ,
"Taylor(2:13 PM): Nice. I will give it a go. Is he that “everybody must get stoned guy”?" ,
"@Taylor(2:14 PM): Yeah I think that’s him. He does like a jimi Hendrix cover of All Along the Watchtower too." ,
"Taylor(2:15 PM): Oh I know that guy. I might try it. Not really my thing. U know im n2 hardcore ganster rap right?" ,
"Taylor(2:16 PM): Wanna play a quick name game? Patterson, hunter, maybin, Gomez, smoak. I really need sb’s but smoak may have a power comeback which I’ll also take." ,
"@Taylor(2:18 PM): Hmm I think I like smoak or hunter out of that group but not a lot of sbs. Not too sure what’s on the wire for speed. Hunter steals some like two a month or he used to anyways." ,
"Taylor(2:20 PM): How bout maybins gr8 walk against the mariners? Nice." ,
"@Taylor(2:22 PM): Ya that’s awesome. Intentionally walk a padre hitting .230 and choke throw it into the stands haha." ,
"Taylor(2:23 PM): Baseball is hard." ,
"@Taylor(2:24 PM): It really is. I’m so frustrated with that league." ,
"Taylor(2:26 PM): I know man. U r in an intense grind man. Circumstances will shift 2 ur favor at some point. Reading extra 2% right now I’ll loan it to you when I’m done." ,
"@Taylor(2:27 PM): Oh cool how is it? I’ll trade you Moneyball for that book and Bautista." ,
"Taylor(2:28 PM): That’s probably fair. Deal. It’s actually really good. Feel like I should have read Moneyball first but it was a dad’s day gift. Didn’t know your Sox were almost the Tampa Bay White Sox.",
"@Taylor(2:30 PM): What the fuck is that true? That would have fucking sucked",
"Taylor(2:31 PM): Apparently so ok will hit you up later bro.",
"@Sonya(3:07 PM): Hi baby. Killing time at fstar how are you?",
"Sonya(3:09 PM): I’m fine. I wish I could meet you at Flying Star :) how’s the project coming?",
"@Sonya(3:11 PM): So far so good just collecting data. I had a random person hit me up and had a little wrong number chain with them. I kept being like who is this? And they thought I was their friend so they kept texting me thinking I was joking.",
"Sonya(3:12 PM): LOL",
"Sonya(3:14 PM): Walkmen in Phoenix on Sept 15 with Fleet Foxes and Bon iver. Road Trip?",
"@Sonya(3:15 PM): Oh man. K I’m down!",
"Taylor(3:14 PM): And dude, u totally had Ogando pegged. I doubted u for dropping him, but now…",
"@Taylor(3:16 PM): Got that one right. His FIP was all fucked up.",
"Taylor(3:18 PM): Gr8 job dork!",
"Sonya(4:17 PM): What size shoe do you wear?",
"@Sonya(4:18 PM): Thirteen. Twelve in Converse.",
"Sonya(4:20 PM): That soccer players name is Hope Solo.",
"@Sonya(4:22 PM): That’s a stage name",
"@August(5:59 PM): Yr grandyman smack haha",
"August(6:01 PM): Thanks bro :) Glad someone got it…",
"Matthew(6:04 PM): I watched “White Fang” today. Did you?",
"@Matthew(6:10 PM): No but I watched a different Ethan Hawke joint. “Explorers”. River Phoenix is in it.",
"@August(6:30 PM): We might go see Walkmen and Fleet Foxes in Phoenix.",
"August(6:31 PM): Oh cool. Same show?",
"@August(6:33 PM): Yeah. Bon Iver is opening I think too.",
"August(6:35 PM): No way. He has the number one record. He’s not an opening act.",
"@August(6:36 PM): Hmm well the other two are fairly big acts so I don’t know then.",
"August(6:37 PM): Maybe. That sounds killer dude. I’m jealous.",
"@August(6:38 PM): Pixies in Santa Fe though! Hells Bells Tour.",
"August(6:39 PM): I just got a little wet.",
"@August(6:40 PM): lmfao",
"Edward(7:24 PM): Hey Vinnie! Matt saw White Fang today!",
"August(7:25 PM): Freakin lame. Sanchez blew me up again…",
"@August(7:27 PM): Romero epic digger. Bad week for me again. :(",
"@August(7:30 PM): Adam throws Masterson against the Yanks and he is freaking dealing. This season has been mentally exhausting dude.",
"Taylor(7:34 PM): You get my enviromentalist poster text?",
"@Taylor(7:36 PM): Oh yeah I did good shit. Meant to hit you up on that.",
"August(8:06 PM): Staci just told me that I’m ruining her life because I don’t want to take her on a vacation that costs $2500. She’s worried about her future…",
"@August(8:08 PM): ? What is that shit about?",
"August(8:09 PM): She says she needs to get out and experience life. And I don’t have those desires so it makes her scared about our future. And that her friends make way less than we do and they all go on vacations…",
"@August(8:11 PM): Well maybe if she got a job that would get her out of the house and experiencing life and understanding the value of money a bit better",
"August(8:12 PM): I agree. We live paycheck to paycheck. Sorry that stresses me out… That 07 VW isn’t paying for iself and neither will the house I’m trying to buy for us. And I’m ruining her existence.",
"@August(8:14 PM): That’s a bunch of horseshit",
"August(8:16 PM): I sort of get why people don’t like to come home from work now…",
"@August(8:17 PM): That’s so unfair to you it really makes me mad",
"August(8:20 PM): I thinks she’s stressed about the kids which is fine but don’t take that out on me like I don’t try and give you what you want and need.",
"Taylor(8:56 PM): My granddad just died.",
"@Taylor(8:57 PM): Oh t I am so truly sorry to hear that man.",
"@August(9:00 PM): Taylor’s grandpa passed away…RIP",
"August(9:01 PM): …Oh bummer…",
"August(9:02 PM): RIP indeed.",
"Brandon(10:13 PM): We found flights to St. Thomas next year for our wedding @ $700 round trip. Pretty cheap, may also get another discount due to group rate depending on how many people can commit now.",
"Brandon(10:15 PM): I know moneys tight, if you guys want to come let me know and I’ll include info in an email…",
};
int index;
int shade=0;
int sat=0;
int bright=0;
void setup() {
size(1024, 768);
textFont(createFont( "Arial", 14, true));
textAlign(CENTER);
rectMode(CENTER);
colorMode(HSB,360,100,100,100);
MidiBus.list();
myBus = new MidiBus(this, -1, "Java Sound Synthesizer");
}
void draw() {
background(0);
printStringToInts(headlines[index]);
colorChange();
fill(shade,sat,bright);
text(headlines[index], width/2, height-200, width/2, 100);
}
// input a string, to be printed as ints to the console
void printStringToInts(String s) {
//declare variables
int note;
int totalChar;
int t=0;
// for the length of the String
for (int i=0; i<s.length(); i++) {
// convert each character in the string to an int
// and print it to the console
note=(int)s.charAt(i);
totalChar=(int)s.length();
println((note)+","+(t)+","+(totalChar)+","+(index));
int channel = 12;
int pitch = note;
int velocity = 127;
myBus.sendNoteOn(channel, note, velocity);
int number = 0;
int value = 90;
myBus.sendControllerChange(channel, number, value);
delay(totalChar/2);
t=t+1;
if (t >= s.length()) {
t=0;
index = (index + 1) % (headlines.length);
}
}
}
//change the color based on who is texting
void colorChange(){
if (index == 1){
shade=300;
sat=53;
bright=99;
}
else if(index==2 || index==7){
shade=124;
sat=99;
bright=99;
}
else if(index==3){
shade=58;
sat=100;
bright=54;
}
else if(index==9||index==11||index==13||index==15||index==17||index==20||index==22){
shade=91;
sat=43;
bright=99;
}
else if(index==18||index==40||index==42||index==43||index==50){
shade=180;
sat=100;
bright=100;
}
else if(index==23||index==25||index==27||index==28||index==30||index==32||index==34||index==36||index==38||index==45||index==47||index==69||index==80){
shade=5;
sat=99;
bright=99;
}
else if(index==53||index==57||index==59||index==61||index==63||index==66||index==71||index==73||index==75||index==77||index==79||index==83||index==84){
shade=229;
sat=91;
bright=100;
}else if(index==54){
shade=318;
sat=24;
bright=76;
}
else if(index==65){
shade=180;
sat=1;
bright=40;
}
else if(index==85||index==86){
shade=174;
sat=34;
bright=99;
}
else{
shade=0;
sat=0;
bright=100;
}
}
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);
}
1