|
| 1 | +loadAPI(17); |
| 2 | + |
| 3 | +host.setShouldFailOnDeprecatedUse(true); |
| 4 | + |
| 5 | +host.defineController("xjadeo", "xJadeo Video Sync", "0.1", "295c10cb-b8d6-416b-9be5-dc2375936ac0", "Trinitou"); |
| 6 | + |
| 7 | +var oscConnection; |
| 8 | + |
| 9 | +var lastOnTopState; |
| 10 | +function invalidateLastOnTopState() { |
| 11 | + lastOnTopState = null; |
| 12 | +} |
| 13 | +function updateOnTop(onTop) { |
| 14 | + if(onTop == lastOnTopState) |
| 15 | + return; |
| 16 | + oscConnection.sendMessage("/jadeo/cmd", "window ontop " + (onTop ? "on" : "off")); |
| 17 | + lastOnTopState = onTop; |
| 18 | + host.println("Sent 'Keep on top' state: " + (onTop ? "on" : "off")); |
| 19 | +} |
| 20 | + |
| 21 | +var lastVideoPath; |
| 22 | +function invalidateLastVideoPath() { |
| 23 | + lastVideoPath = null; |
| 24 | +} |
| 25 | +function updateVideo(path) { |
| 26 | + if (path === lastVideoPath) |
| 27 | + return false; |
| 28 | + oscConnection.sendMessage("/jadeo/load", path); // sending an empty path will close current video file |
| 29 | + host.println("Sent video path: '" + path + "'"); |
| 30 | + lastVideoPath = path; |
| 31 | + return true; |
| 32 | +} |
| 33 | + |
| 34 | +var lastFrame; |
| 35 | +function invalidateLastFrame() { |
| 36 | + lastFrame = -1; |
| 37 | +} |
| 38 | +function updateFrame(frame) { |
| 39 | + if (oscConnection == null) { |
| 40 | + invalidateLastFrame(); |
| 41 | + return; |
| 42 | + } |
| 43 | + if (frame != lastFrame) { |
| 44 | + oscConnection.sendMessage("/jadeo/seek", frame); |
| 45 | + lastFrame = frame; |
| 46 | + // host.println("Sent frame: " + lastFrame); |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +function invalidateAll() { |
| 51 | + invalidateLastOnTopState(); |
| 52 | + invalidateLastVideoPath(); |
| 53 | + invalidateLastFrame(); |
| 54 | +} |
| 55 | + |
| 56 | +var onTopSetting; |
| 57 | +var pathSetting; |
| 58 | +var frameRateSetting; |
| 59 | +var pos; |
| 60 | + |
| 61 | +function init() { |
| 62 | + oscConnection = host.getOscModule().connectToUdpServer("localhost", 12345, null); |
| 63 | + |
| 64 | + let prefs = host.getPreferences(); |
| 65 | + |
| 66 | + onTopSetting = prefs.getBooleanSetting("Keep on top", "Video window", true); |
| 67 | + onTopSetting.markInterested(); |
| 68 | + |
| 69 | + let docState = host.getDocumentState(); |
| 70 | + |
| 71 | + pathSetting = docState.getStringSetting("Path", "File", 256, ""); |
| 72 | + pathSetting.markInterested(); |
| 73 | + |
| 74 | + frameRateSetting = docState.getNumberSetting("FPS", "File", 24, 60, 0.01, "", 24); |
| 75 | + frameRateSetting.markInterested(); |
| 76 | + |
| 77 | + // add flush command to both the preferences and document state for easy access: |
| 78 | + let settings = [prefs, docState]; |
| 79 | + for(var i = 0; i < settings.length; i++) { |
| 80 | + settings[i].getSignalSetting("Flush", "Video window", "Flush!").addSignalObserver(function () { |
| 81 | + invalidateAll(); |
| 82 | + }); |
| 83 | + } |
| 84 | + |
| 85 | + pos = host.createTransport().playPositionInSeconds(); |
| 86 | + pos.markInterested(); |
| 87 | + |
| 88 | + invalidateAll(); |
| 89 | + |
| 90 | + println("xJadeo Connect initialized!"); |
| 91 | +} |
| 92 | + |
| 93 | +function flush() { |
| 94 | + updateOnTop(onTopSetting.get()); |
| 95 | + if (updateVideo(pathSetting.get())) |
| 96 | + invalidateLastFrame(); |
| 97 | + updateFrame(Math.floor(pos.get() * frameRateSetting.getRaw())); |
| 98 | +} |
| 99 | + |
| 100 | +function exit() { |
| 101 | + updateVideo(""); |
| 102 | +} |
0 commit comments