|
- import VLCJVideo.*;
-
-
- import themidibus.*; //Import the library
- import processing.video.*;
-
- MidiBus midiBus; // The MidiBus
- VLCJVideo currentVideo;
- JSONObject json;
- JSONArray jsonVideos;
- int listeningChannel;
- /*Videos map with pitches as keys*/
- HashMap<Integer,VLCJVideo> videos = new HashMap<Integer,VLCJVideo>();
-
-
- import static javax.swing.JOptionPane.*;
- void setup() {
- //load pitch/movie mapping from json and populate the movies map
- json = loadJSONObject("config.json");
- int midiDevice = -1;
- try{
- midiDevice = json.getInt("midiDevice");
- listeningChannel = json.getInt("channel") + 1;
- }
- catch(Exception ex){
- MidiBus.list(); // List all available Midi devices on STDOUT. This will show each device's index and name.
- showMessageDialog(null,"Midi device is missing into your configuration file. Check the console to find it.");
- System.exit(-1);
- }
- jsonVideos = json.getJSONArray("videos");
-
- for(int i = 0; i < jsonVideos.size();i++){
- JSONObject v = jsonVideos.getJSONObject(i);
- Integer key = v.getInt("key");
- VLCJVideo video = new VLCJVideo(this);
- video.openMedia(v.getString("file"));
- videos.put(key,video);
- if(i == 0)
- currentVideo = video;
- }
- background(0);
- initMidi(midiDevice);
- }
-
- void initMidi(int midiDevice){
-
- // Parent In Out
- // | | |
- //myBus = new MidiBus(this, 0, 1);
- // Create a new MidiBus using the device index to select the Midi input and output devices respectively.
-
- // or ...
- // Parent In Out
- // | | |
- //myBus = new MidiBus(this, "IncomingDeviceName", "OutgoingDeviceName");
- // Create a new MidiBus using the device names to select the Midi input and output devices respectively.
- midiBus = new MidiBus(this, midiDevice, midiDevice);
- }
-
- void draw() {
- background(0);
- image(currentVideo, 0, 0, width, height);
- }
-
- public void settings() {
- fullScreen();
- }
-
- void noteOn(int channel, int pitch, int velocity) {
- try{
- if(channel != listeningChannel)
- return;
- println("Note On:");
- println("Pitch:"+pitch);
- //stop and rewind current movie
- currentVideo.stop();
- currentVideo.jump(0);
- //get current movie according to pich value
- currentVideo = videos.get(pitch);
- //play movie
- currentVideo.play();
- currentVideo.mute();
- }
- catch(Exception e){
- showMessageDialog(null,e.getMessage());
- System.exit(-1);
- }
-
- }
-
- void noteOff(int channel, int pitch, int velocity) {
- //nothin' to do
- }
|