I am not sure how to read a text file that is being updated elsewhere. The file is being updated every three seconds in which when the tweets fall to the bottom of the page the txt file is having it's first entry deleted. When I run it though the text file remains the same in processing until I restart the app.
Any help much appreciated thanks!
nb. I have posted this here instead of contributed library because maxlink is not relevant to the question. Sorry if it should not be here.
MaxLink linkin = new MaxLink(this, "tweets"); ArrayList<Tweets> tweets; import maxlink.*;
void setup() {
size(600,600); textAlign(CENTER);
tweets = new ArrayList<Tweets>(); tweets.add(new Tweets());
I am trying to create an installation that saves up tweets on a particular topic and stores them in a text file. I have this working using coll in Max msp to save the files from Processing. When a bucket is poured(via arduino) I would like the tweets to fall down the screen like rain. I can store and update the txt file fine, but the problems I am having is to retrieve the tweets one by one and get them to fall down the screen. Also I would like the tweets to be deleted from the text file after they have fallen to the bottom of the screen.
Any help would be very much appreciated thankyou!
import processing.pdf.*; import java.util.Date; import maxlink.*; MaxLink link = new MaxLink(this, "twits"); MaxLink linkin = new MaxLink(this, "twoots"); static String OAuthConsumerKey = "mykey"; static String OAuthConsumerSecret = "secret"; static String AccessToken = "at"; static String AccessTokenSecret = "dd"; String myTimeline; java.util.List statuses = null; User[] friends; TwitterFactory twitterFactory; Twitter twitter; RequestToken requestToken; String[] theSearchTweets = new String[11]; String myQueryWord = "#water"; long previousIdOfTweetContainingQuery = 0; public ArrayList tweets; public String msg; //the tweets public int a; // from max msp; public int y = 0; // to move words down page public int x = 0; // public float speed; // to create random speeds
private static AccessToken loadAccessToken() { return new AccessToken(AccessToken, AccessTokenSecret); // get my oauth details }
void draw() { getSearch(); // retrieve tweets to max and sore them in "tweets.txt"
y =y +7; // increase y position of tweets String[] lines = loadStrings("tweeters.txt"); //This doesn't work at all really but is the kind of thing I want to do. for (int i = 0; i < lines.length; i++) { text(lines[i], random(600), y, 50, 50); } }
void getSearch() {
try { println ("Searching.... Current time = " + hour() + ":" + minute() + ":" + second()); Query query = new Query(myQueryWord);
query.count(50); // how many results to fetch
QueryResult result = twitter.search(query);
ArrayList tweetsContainingQuery = (ArrayList) result.getTweets(); if (tweetsContainingQuery.size() > 0) { Status mostRecentTweetContainingQuery = (Status) tweetsContainingQuery.get(0); long mostRecentTweetContainingQueryId = mostRecentTweetContainingQuery.getId();
if (previousIdOfTweetContainingQuery == 0) { previousIdOfTweetContainingQuery = mostRecentTweetContainingQueryId; } if (mostRecentTweetContainingQueryId != previousIdOfTweetContainingQuery) { // my word is tweeted previousIdOfTweetContainingQuery = mostRecentTweetContainingQueryId; Date d = mostRecentTweetContainingQuery.getCreatedAt(); msg = mostRecentTweetContainingQuery.getText();
link.output(msg); // send and store in coll/"tweeters.txt" } } }
catch (TwitterException te) { println("Error connecting to Twitter: " + te); //let me know if somethings not right }; delay(3000); }
I am having trouble getting this to work. I want to add drops when an accelerometer is titled and remove drops when it returns to normal. Where am I going wrong? Thanks.
import maxlink.*;
ArrayList<Rain> drops; int r = 60; public float a;
Hi, I am writing a small program using Arduino, Processing and SC. The idea is that an accelerometer will be placed in a watering can and when tipped the screen will display raindrops. When the raindrops hit the bottom of the screen(y height) they will make a sound. Ideally I would like each raindrop to have an individual sound. I am from a Max msp background and if it was max I would say that I would like each raindrop to be a separate groove object so that the raindrops can begin to make chords and melodies.
Currently the SC server cannot process the information fast enough so there are large gaps between sound. Could anyone help me out with this? I would prefer it if you could guide me to a solution rather than just giving me the code, otherwise I will never learn!
Apologies about the long post here is my code currently.
import supercollider.*; import oscP5.*; Rain r1;
Synth synth;
ArrayList<Rain> drops;
void setup() { size(600, 600); drops = new ArrayList<Rain>(); drops.add(new Rain()); synth = new Synth("sine"); //Should I be creating an array of synths?
void mousePressed() { drops.add(new Rain()); //This is where I will add the arduino }
void exit() { synth.free(); super.exit(); }
class Rain { float r = random(600); float y = random(-height);
void fall() { y = y + 7; fill(0, 10, 200, 180); ellipse(r, y, 10, 10);
if (y>height) { r = random(600); y = random(-200); synth.set("freq", r); synth.set("amp", 0.5); } else if (y >height - height/2){ synth.set("amp", 0); } //This is probably a really stupid way to try and get the synth to // make a short noise } } }