help sought with twitter triggered midi commands project
in
Contributed Library Questions
•
7 months ago
hi
i am relatively new to processing and am trying to realise a project i initially intended to carry out on an Arduino. I built a number of OSC controlled birdboxes for a garden space here in Liverpool (short video explaining them can be found here:
https://vimeo.com/46490448) .
I wanted to improve these by having them respond to twitter, based on specified search commands, the idea being that everytime a certain # is used a simple midi command is sent to ableton live which in turn sends a series of OSC commands and plays back audio files across the 4 birdboxes i have installed.
With the changes to the twitter API coming into effect as of the end of this month the arduino solution i sought is not going to work. I am trying to find an alternative solution and have managed to coble something together in processing that can query twitter and bring back results, i have also managed to get the midi side of things working (in terms of sending midi notesON out of processing into ableton) .. I just don't really know how to join the two up, what i need is the processing app to query twitter at set intervals and see if any new tweets have been posted, if they have send MIDI NOTE ON..
the code I have so far:
- import java.util.Date;
- ConfigurationBuilder cb;
- Twitter twitter;
- void setup() {
- cb = new ConfigurationBuilder();
- cb.setOAuthConsumerKey("xxxxxxxxxxxxxxx");
- cb.setOAuthConsumerSecret("xxxxxxxxxxxxxxxxxx");
- cb.setOAuthAccessToken("xxxxxxxxxxxxxxxxxxxxxxxxx");
- cb.setOAuthAccessTokenSecret("xxxxxxxxxxxxxxxxxxxxxx");
- twitter = new TwitterFactory(cb.build()).getInstance();
- Query query = new Query("thekazimier");
- query.setCount(100);
- try {
- QueryResult result = twitter.search(query);
- ArrayList tweets = (ArrayList) result.getTweets();
- for (int i = 0; i < tweets.size(); i++) {
- Status t = (Status) tweets.get(i);
- User u=(User) t.getUser();
- String user=u.getName();
- String msg = t.getText();
- Date d = t.getCreatedAt();
- println("Tweet by " + user + " at " + d + ": " + msg);
- };
- }
- catch (TwitterException te) {
- println("Couldn't connect: " + te);
- };
- }
- void draw() {
- }
this succesfully queries twitter..and brings back results.. but doesn't actually identify if any new tweets have been posted since last query..
the midi code is just the sample code that comes with the midibus library:
- import themidibus.*; //Import the library
- MidiBus myBus; // The MidiBus
- void setup() {
- size(400, 400);
- background(0);
- MidiBus.list(); // List all available Midi devices on STDOUT. This will show each device's index and name.
- myBus = new MidiBus(this, 0, 0 ); // Create a new MidiBus with no input device and the default Java Sound Synthesizer as the output device.
- }
- void draw() {
- int channel = 0;
- int pitch = 64;
- int velocity = 127;
- myBus.sendNoteOn(channel, pitch, velocity); // Send a Midi noteOn
- delay(200);
- myBus.sendNoteOff(channel, pitch, velocity); // Send a Midi nodeOff
- int number = 0;
- int value = 90;
- delay(2000);
- }
- void delay(int time) {
- int current = millis();
- while (millis () < current+time) Thread.yield();
- }
I was hoping might be able to point me in the right direction how to merge the two codes.. any help is greatly appreciated..
1