Skip to content

Commit

Permalink
Added TouchOSC
Browse files Browse the repository at this point in the history
  • Loading branch information
UUoocl authored May 21, 2024
1 parent 0574812 commit aa48cd7
Show file tree
Hide file tree
Showing 9 changed files with 498 additions and 390 deletions.
55 changes: 37 additions & 18 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<head>
<meta charset="UTF-8">
<title>ZoomOSC to OBS WebSocket Server</title>
<title>OSC to OBS WebSocket Server</title>
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=700, user-scalable=no" />
Expand All @@ -19,11 +19,10 @@
<a href="#srvr">Servers</a>
<ul>
<li><a href="#srvr-obs-ws">OBS WebSocket Server</a></li>
<li><a href="#srvr-osc">OSC Server</a></li>

<li><a href="#zoom-osc">ZoomOSC</a></li>
<li><a href="#touch-osc">TouchOSC</a></li>
</ul>
</li>


</ul>
<svg class="toc-marker" width="200" height="200" xmlns="http://www.w3.org/2000/svg">
Expand All @@ -34,15 +33,11 @@

<article class="contents">
<section id="intro">
<h2>ZoomOSC to OBS WebSocket Server</h2>
<h2>OSC to OBS WebSocket Server</h2>

</section>

<section>
<div id="srvr">
<h2>Connections</h2>
<p></p>
</div>
<div id="srvr-obs-ws">
<h3>OBS WebSocket Server</h3>
<p><label for="IP">Enter IP address or "localhost":</label>
Expand All @@ -54,24 +49,48 @@ <h3>OBS WebSocket Server</h3>
<input type="button" id="WSconnectButton" value="Connect to OBS" /><br>
</p>
</div>
</section>

<div id="srvr-osc">
<h3>Open Sound Control Server</a></h3>
<p><label for="oscIP">Enter OSC IP address or "localhost":</label>
<section>
<div id="zoom-osc">
<h3>ZoomOSC connection</a></h3>
<p><label for="oscIP">Enter ZoomOSC IP address or "localhost":</label>
<input type="text" id="oscIP" name="oscIP" value="127.0.0.1" /><br>
<label for="oscInPORT">Enter OSC In (receive) Port Number:</label>
<label for="oscInPORT">Enter ZoomOSC In (receive) Port Number:</label>
<input type="text" id="oscInPORT" name="oscInPort" value="1234" /><br>
<label for="oscOutPORT">Enter OSC Out (transport) Port Number:</label>
<label for="oscOutPORT">Enter ZoomOSC Out (transport) Port Number:</label>
<input type="text" id="oscOutPORT" name="oscOutPort" value="9090" /><br>
<input type="button" id="oscButton" value="Create OSC Server" />
<input type="button" id="oscButton" value="Create ZoomOSC Server and Client" />
</p>
<p>Messages from ZoomOSC to OBS</p>
<div id="zoomInMessages"></div>
<p>Messages from OBS to ZoomOSC</p>
<div id="zoomOutMessages"></div>
</div>
</section>

<section>
<div id="touch-osc">
<h3>TouchOSC connection</a></h3>
<p><label for="toscIP">Enter TouchOSC IP address or "localhost":</label>
<input type="text" id="toscIP" name="toscIP" value="127.0.0.1" /><br>
<label for="toscInPORT">Enter TouchOSC In (receive) Port Number:</label>
<input type="text" id="toscInPORT" name="toscInPort" value="2345" /><br>
<label for="toscOutPORT">Enter TouchOSC Out (transport) Port Number:</label>
<input type="text" id="toscOutPORT" name="toscOutPort" value="9092" /><br>
<input type="button" id="toscButton" value="Create TouchOSC Server and Client" />
</p>
<p>Messages from TouchOSC to OBS</p>
<div id="touchInMessages"></div>
<p>Messages from OBS to TouchOSC</p>
<div id="touchOutMessages"></div>
</div>
</section>


</article>

<div class="credits">
<a href="https://github.com/UUoocl/ZoomOSC_to_OBS_WebSocket">Source on GitHub</a>
<a href="https://github.com/UUoocl/OSC_to_OBS_WebSocket">Source on GitHub</a>
</div>

<style type="text/css" media="screen">
Expand Down Expand Up @@ -111,4 +130,4 @@ <h3>Open Sound Control Server</a></h3>
</style>
</body>

</html>
</html>
137 changes: 67 additions & 70 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const { app, BrowserWindow, ipcMain } = require("electron/main");
const path = require("path");
const fs = require("fs");
const oscServer = require("node-osc");


const { electron } = require("process");

//window variables
let mainWindow, oscWindow;
Expand All @@ -24,12 +20,6 @@ app.whenReady().then(() => {
}
});
});

app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
//#endregion

//#region create main window
Expand All @@ -42,80 +32,37 @@ async function createWindow() {
y: 0,
title: __dirname,
webPreferences: {
sandbox: false,
nodeIntegration: true,
backgroundThrottling: false,
preload: path.join(__dirname, "preload.js"),
},
});

// and load the index.html of the app.
mainWindow.loadFile("index.html");

// Open the DevTools.
//mainWindow.webContents.openDevTools();
mainWindow.webContents.openDevTools();
}
//#endregion

//#region Open-osc-windows
ipcMain.on(
"open-osc-window",
(event, IP, Port, PW, oscIP, oscInPORT, oscOutPORT) => {
console.log("main received osc window IPC");
oscWindow = new BrowserWindow({
width: 400,
height: 400,
x: 200,
y: 100,
title: "osc window",
frame: true,
resizable: true,
//roundedCorners: false,
movable: true,
titleBarOverlay: false,
transparent: false,
titleBarStyle: "default",
webPreferences: {
sandbox: false,
nodeIntegration: true,
backgroundThrottling: false,
preload: path.join(__dirname, "osc-preload.js"),
},
});

windowSetup = {
websocketIP: IP,
websocketPort: Port,
websocketPassword: PW,
oscInPORT: oscInPORT,
oscOutPORT: oscOutPORT,
oscIP: oscIP,
};
//console.log(windowSetup)
oscWindow.loadFile("osc.html");
//oscWindow.webContents.openDevTools()
}
);
//#endregion

//#region IPC APIs
//Send websocket and projector window to renderer
ipcMain.handle("get-obsWSdetails", async () => {
console.log("sending window details to a new window");
console.log(windowSetup);
return windowSetup;
});

//#region IPC set OBS connection
ipcMain.on("set-obs-connection", async (event, IP, Port, PW) => {
console.log("setting OBS Connection");

webSocketDetails = {
websocketIP: IP,
websocketPort: Port,
websocketPassword: PW,
websocketPassword: PW
};
console.log(
webSocketDetails.websocketIP,
webSocketDetails.websocketPort,
webSocketDetails.websocketPassword
webSocketDetails.websocketPassword,
userPath
);
//write to file
let sData = JSON.stringify(webSocketDetails);
Expand All @@ -135,17 +82,67 @@ ipcMain.handle("get-obs-connection", async (event) => {
return data;
}
});
//#endregion

ipcMain.on("wsConnect", (event) => {
console.log("sending websocket details to new window");
console.log(webSocketDetails);
event.returnValue = webSocketDetails;
//#region IPC set ZoomOSC connection
ipcMain.on("save-zosc-settings", async (event, oscIP, oscInPort, oscOutPort) => {
console.log("save settings ZoomOSC");
let zoscDetails = {
oscIP: oscIP,
oscInPort: oscInPort,
oscOutPort: oscOutPort
};
const sData = JSON.stringify(zoscDetails);
const userpath = app.getPath("userData");
fs.writeFileSync(`${userpath}/zoomOSC_setting.txt`, sData);
});

ipcMain.handle("get-zoomosc-connection", async (event) => {
console.log("get ZoomOsc default settings");
const userpath = app.getPath("userData");
console.log(`${userpath}/zoomOSC_setting.txt`);
console.log(fs.existsSync(`${userpath}/zoomOSC_setting.txt`));
//console.log(fs.exists(`${userpath}/zoomOSC_setting.txt`))
if (fs.existsSync(`${userpath}/zoomOSC_setting.txt`)) {
let dt = fs.readFileSync(`${userpath}/zoomOSC_setting.txt`);
let data = JSON.parse(dt);
console.log(data);
return data;
}
});

//#region IPC set TouchOSC connection
ipcMain.on("save-tosc-settings", async (event, oscIP, oscInPort, oscOutPort) => {
console.log("save settings TouchOSC");
let toscDetails = {
oscIP: oscIP,
oscInPort: oscInPort,
oscOutPort: oscOutPort
};
const sData = JSON.stringify(toscDetails);
const userpath = app.getPath("userData");
fs.writeFileSync(`${userpath}/touchOSC_setting.txt`, sData);
});

ipcMain.handle("get-touchosc-connection", async (event) => {
console.log("get touchOsc default settings");
const userpath = app.getPath("userData");
console.log(`${userpath}/touchOSC_setting.txt`);
console.log(fs.existsSync(`${userpath}/touchOSC_setting.txt`));
//console.log(fs.exists(`${userpath}/zoomOSC_setting.txt`))
if (fs.existsSync(`${userpath}/touchOSC_setting.txt`)) {
let dt = fs.readFileSync(`${userpath}/touchOSC_setting.txt`);
let data = JSON.parse(dt);
console.log(data);
return data;
}
});
//#endregion

// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on("window-all-closed", function () {
if (process.platform !== "darwin") app.quit();
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
Loading

0 comments on commit aa48cd7

Please sign in to comment.