Launches movies on midi note events.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.5 KiB

  1. import VLCJVideo.*;
  2. import themidibus.*; //Import the library
  3. import processing.video.*;
  4. MidiBus midiBus; // The MidiBus
  5. VLCJVideo currentVideo;
  6. JSONObject json;
  7. JSONArray jsonVideos;
  8. int listeningChannel;
  9. /*Videos map with pitches as keys*/
  10. HashMap<Integer,VLCJVideo> videos = new HashMap<Integer,VLCJVideo>();
  11. import static javax.swing.JOptionPane.*;
  12. void setup() {
  13. //load pitch/movie mapping from json and populate the movies map
  14. json = loadJSONObject("config.json");
  15. int midiDevice = -1;
  16. try{
  17. midiDevice = json.getInt("midiDevice");
  18. listeningChannel = json.getInt("channel") + 1;
  19. }
  20. catch(Exception ex){
  21. MidiBus.list(); // List all available Midi devices on STDOUT. This will show each device's index and name.
  22. showMessageDialog(null,"Midi device is missing into your configuration file. Check the console to find it.");
  23. System.exit(-1);
  24. }
  25. jsonVideos = json.getJSONArray("videos");
  26. for(int i = 0; i < jsonVideos.size();i++){
  27. JSONObject v = jsonVideos.getJSONObject(i);
  28. Integer key = v.getInt("key");
  29. VLCJVideo video = new VLCJVideo(this);
  30. video.openMedia(v.getString("file"));
  31. videos.put(key,video);
  32. if(i == 0)
  33. currentVideo = video;
  34. }
  35. background(0);
  36. initMidi(midiDevice);
  37. }
  38. void initMidi(int midiDevice){
  39. // Parent In Out
  40. // | | |
  41. //myBus = new MidiBus(this, 0, 1);
  42. // Create a new MidiBus using the device index to select the Midi input and output devices respectively.
  43. // or ...
  44. // Parent In Out
  45. // | | |
  46. //myBus = new MidiBus(this, "IncomingDeviceName", "OutgoingDeviceName");
  47. // Create a new MidiBus using the device names to select the Midi input and output devices respectively.
  48. midiBus = new MidiBus(this, midiDevice, midiDevice);
  49. }
  50. void draw() {
  51. background(0);
  52. image(currentVideo, 0, 0, width, height);
  53. }
  54. public void settings() {
  55. fullScreen();
  56. }
  57. void noteOn(int channel, int pitch, int velocity) {
  58. try{
  59. if(channel != listeningChannel)
  60. return;
  61. println("Note On:");
  62. println("Pitch:"+pitch);
  63. //stop and rewind current movie
  64. currentVideo.stop();
  65. currentVideo.jump(0);
  66. //get current movie according to pich value
  67. currentVideo = videos.get(pitch);
  68. //play movie
  69. currentVideo.play();
  70. currentVideo.mute();
  71. }
  72. catch(Exception e){
  73. showMessageDialog(null,e.getMessage());
  74. System.exit(-1);
  75. }
  76. }
  77. void noteOff(int channel, int pitch, int velocity) {
  78. //nothin' to do
  79. }