commit 850d570e2ce62becceafe1e5931bc53a87402133 Author: Jérôme Date: Mon Jul 8 21:06:59 2019 +0200 First functionnal version. diff --git a/README.md b/README.md new file mode 100644 index 0000000..83d400c --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +MDMV +========= +Launches movies on midi note events. +Notes to videos mapping is done in the data/config.json file. + +# Requirements + +* Processing 3.5.3 +* [https://github.com/linux-man/VLCJVideo](VLCJVideo) +* [https://github.com/sparks/themidibus](Midibus) + + VLCJVideo & Midibus are both available from the Processing + package manager. diff --git a/data/.DS_Store b/data/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/data/.DS_Store differ diff --git a/data/config.json b/data/config.json new file mode 100755 index 0000000..256b23a --- /dev/null +++ b/data/config.json @@ -0,0 +1,47 @@ +{ +"midiDevice": 0, +"channel":16, +"videos": [ + { + "file": "1.mov", + "key": 108 + }, + { + "file": "2.mov", + "key": 109 + }, + { + "file": "3.mov", + "key": 110 + }, + { + "file": "4.mov", + "key": 111 + }, + { + "file": "5.mov", + "key": 112 + }, + { + "file": "6.mov", + "key": 113 + }, + { + "file": "7.mov", + "key": 114 + }, + { + "file": "8.mov", + "key": 115 + }, + { + "file": "9.mov", + "key": 116 + }, + { + "file": "10.mov", + "key": 117 + } + ] +} +//https://newt.phys.unsw.edu.au/jw/notes.html diff --git a/mdmv.pde b/mdmv.pde new file mode 100644 index 0000000..fbb76b2 --- /dev/null +++ b/mdmv.pde @@ -0,0 +1,93 @@ +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 videos = new HashMap(); + + +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 +}