Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion companion/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
},
"manufacturer": "Generic",
"products": ["OSC"],
"keywords": ["Protocol", "Generic"]
"keywords": ["Protocol", "Generic"],
"type": "connection"
}
6 changes: 3 additions & 3 deletions osc-feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async function onDataHandler(root, data) {
root.onDataReceived[packet.address] = [{ type: 'i', value: null }];
root.log('debug', `OSC message: ${packet.address}, args: Null (${root.onDataReceived[packet.address]})`);

await root.checkFeedbacks();
await root.checkAllFeedbacks();
//Update Variables
root.setVariableValues({
latest_received_raw: `${packet.address}`,
Expand All @@ -70,7 +70,7 @@ async function onDataHandler(root, data) {

root.log('debug', `OSC message: ${packet.address}, args: ${args_json}`);

await root.checkFeedbacks();
await root.checkAllFeedbacks();

//Update Variables
root.setVariableValues({
Expand All @@ -85,7 +85,7 @@ async function onDataHandler(root, data) {
root.onDataReceived[element.address] = element.args;
root.log('debug', `Bundle element message: ${element.address}, args: ${JSON.stringify(element.args)}`);

await root.checkFeedbacks();
await root.checkAllFeedbacks();

//Update Variables
root.setVariableValues({
Expand Down
128 changes: 75 additions & 53 deletions osc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const { InstanceBase, Regex, runEntrypoint } = require('@companion-module/base');
const { InstanceBase, Regex } = require('@companion-module/base');
const UpgradeScripts = require('./upgrades');
const { resolveHostname, isValidIPAddress, parseArguments, evaluateComparison, setupOSC } = require('./helpers.js');

function optionToString(value) {
return value === undefined || value === null ? '' : String(value);
}

class OSCInstance extends InstanceBase {
constructor(internal) {
super(internal);
Expand Down Expand Up @@ -211,7 +215,7 @@ class OSCInstance extends InstanceBase {
},
],
callback: async (event) => {
const path = await this.parseVariablesInString(String(event.options.path ?? ''));
const path = optionToString(event.options.path);

sendOscMessage(path, []);
},
Expand All @@ -236,8 +240,8 @@ class OSCInstance extends InstanceBase {
},
],
callback: async (event) => {
const path = await this.parseVariablesInString(String(event.options.path ?? ''));
const int = await this.parseVariablesInString(String(event.options.int ?? ''));
const path = optionToString(event.options.path);
const int = optionToString(event.options.int);

sendOscMessage(path, [
{
Expand Down Expand Up @@ -267,8 +271,8 @@ class OSCInstance extends InstanceBase {
},
],
callback: async (event) => {
const path = await this.parseVariablesInString(String(event.options.path ?? ''));
const float = await this.parseVariablesInString(String(event.options.float ?? ''));
const path = optionToString(event.options.path);
const float = optionToString(event.options.float);

sendOscMessage(path, [
{
Expand Down Expand Up @@ -297,8 +301,8 @@ class OSCInstance extends InstanceBase {
},
],
callback: async (event) => {
const path = await this.parseVariablesInString(String(event.options.path ?? ''));
const string = await this.parseVariablesInString(String(event.options.string ?? ''));
const path = optionToString(event.options.path);
const string = optionToString(event.options.string);

sendOscMessage(path, [
{
Expand Down Expand Up @@ -328,8 +332,8 @@ class OSCInstance extends InstanceBase {
},
],
callback: async (event) => {
const path = await this.parseVariablesInString(String(event.options.path ?? ''));
const args = await this.parseVariablesInString(String(event.options.arguments ?? ''));
const path = optionToString(event.options.path);
const args = event.options.arguments ?? '';

function tokenize(input) {
if (!input || input.trim() === '') {
Expand Down Expand Up @@ -416,7 +420,7 @@ class OSCInstance extends InstanceBase {
},
],
callback: async (event) => {
const path = await this.parseVariablesInString(String(event.options.path ?? ''));
const path = optionToString(event.options.path);
let type = 'F';
if (event.options.value === true) {
type = 'T';
Expand Down Expand Up @@ -451,7 +455,6 @@ class OSCInstance extends InstanceBase {
id: 'blob',
default: '',
useVariables: true,
isVisible: (options, data) => options.hexswitch === false,
isVisibleExpression: '$(options:hexswitch) === false',
},
{
Expand All @@ -460,7 +463,6 @@ class OSCInstance extends InstanceBase {
id: 'blob_hex',
default: '0A0B0C',
useVariables: true,
isVisible: (options, data) => options.hexswitch === true,
isVisibleExpression: '$(options:hexswitch) === true',
},
{
Expand All @@ -471,9 +473,9 @@ class OSCInstance extends InstanceBase {
},
],
callback: async (event) => {
const path = await this.parseVariablesInString(String(event.options.path ?? ''));
const blob = await this.parseVariablesInString(String(event.options.blob ?? ''));
const blob_hex = await this.parseVariablesInString(String(event.options.blob_hex ?? ''));
const path = optionToString(event.options.path);
const blob = optionToString(event.options.blob);
const blob_hex = optionToString(event.options.blob_hex);

let blobBuffer;

Expand Down Expand Up @@ -543,9 +545,9 @@ class OSCInstance extends InstanceBase {
default: 'equal',
},
],
callback: async (feedback, context) => {
const path = await context.parseVariablesInString(String(feedback.options.path ?? ''));
const targetValueStr = await context.parseVariablesInString(String(feedback.options.arguments ?? ''));
callback: async (feedback) => {
const path = optionToString(feedback.options.path);
const targetValueStr = optionToString(feedback.options.arguments);
const comparison = feedback.options.comparison;

this.log('debug', `Evaluating feedback ${feedback.id}.`);
Expand Down Expand Up @@ -605,9 +607,9 @@ class OSCInstance extends InstanceBase {
default: 'equal',
},
],
callback: async (feedback, context) => {
const path = await context.parseVariablesInString(String(feedback.options.path ?? ''));
const targetValueStr = await context.parseVariablesInString(String(feedback.options.arguments ?? ''));
callback: async (feedback) => {
const path = optionToString(feedback.options.path);
const targetValueStr = optionToString(feedback.options.arguments);
const comparison = feedback.options.comparison;

this.log('debug', `Evaluating feedback ${feedback.id}.`);
Expand Down Expand Up @@ -667,8 +669,8 @@ class OSCInstance extends InstanceBase {
default: 'equal',
},
],
callback: async (feedback, context) => {
const path = await context.parseVariablesInString(String(feedback.options.path ?? ''));
callback: async (feedback) => {
const path = optionToString(feedback.options.path);
const targetValue = feedback.options.arguments;
const comparison = feedback.options.comparison;

Expand Down Expand Up @@ -718,9 +720,9 @@ class OSCInstance extends InstanceBase {
default: 'equal',
},
],
callback: async (feedback, context) => {
const path = await context.parseVariablesInString(String(feedback.options.path ?? ''));
const targetValue = await context.parseVariablesInString(String(feedback.options.arguments ?? ''));
callback: async (feedback) => {
const path = optionToString(feedback.options.path);
const targetValue = optionToString(feedback.options.arguments);
const comparison = feedback.options.comparison;

this.log('debug', `Evaluating feedback ${feedback.id}.`);
Expand Down Expand Up @@ -774,9 +776,9 @@ class OSCInstance extends InstanceBase {
default: 'equal',
},
],
callback: async (feedback, context) => {
const path = await context.parseVariablesInString(String(feedback.options.path ?? ''));
let argsStr = await context.parseVariablesInString(String(feedback.options.arguments ?? ''));
callback: async (feedback) => {
const path = optionToString(feedback.options.path);
let argsStr = optionToString(feedback.options.arguments);
const comparison = feedback.options.comparison;

this.log('debug', `Evaluating feedback ${feedback.id}.`);
Expand Down Expand Up @@ -816,7 +818,7 @@ class OSCInstance extends InstanceBase {
id: 'path',
default: '/osc/path',
useVariables: true,
required: true,
requiredExpression: 'true',
},
{
type: 'textinput',
Expand All @@ -825,7 +827,7 @@ class OSCInstance extends InstanceBase {
default: 0,
regex: Regex.NUMBER,
useVariables: true,
required: true,
requiredExpression: 'true',
},
{
type: 'textinput',
Expand All @@ -843,7 +845,6 @@ class OSCInstance extends InstanceBase {
{ id: 'notequal', label: '!=' },
],
default: 'equal',
isVisible: (options, data) => Number.isFinite(options.arguments) === false,
isVisibleExpression: 'isNumber($(options:arguments)) === false',
},
{
Expand All @@ -859,14 +860,13 @@ class OSCInstance extends InstanceBase {
{ id: 'notequal', label: '!=' },
],
default: 'equal',
isVisible: (options, data) => Number.isFinite(options.arguments) === true,
isVisibleExpression: 'isNumber($(options:arguments)) === true',
},
],
callback: async (feedback, context) => {
const path = await context.parseVariablesInString(String(feedback.options.path ?? ''));
const _index = await context.parseVariablesInString(String(feedback.options.index ?? ''));
const rawValue = await context.parseVariablesInString(String(feedback.options.arguments ?? ''));
callback: async (feedback) => {
const path = optionToString(feedback.options.path);
const _index = feedback.options.index ?? '';
const rawValue = feedback.options.arguments ?? '';

const comparison_number = feedback.options.comparison_number;
const comparison_string = feedback.options.comparison_string;
Expand Down Expand Up @@ -965,8 +965,8 @@ class OSCInstance extends InstanceBase {
useVariables: true,
},
],
callback: async (feedback, context) => {
const path = await context.parseVariablesInString(String(feedback.options.path ?? ''));
callback: async (feedback) => {
const path = optionToString(feedback.options.path);
this.log('debug', `Evaluating feedback ${feedback.id}.`);

if (this.onDataReceived.hasOwnProperty(path) && this.onDataReceived[path].length > 0) {
Expand All @@ -979,23 +979,45 @@ class OSCInstance extends InstanceBase {
}
},
},
osc_feedback_value: {
type: 'boolean',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be type: 'value'.

name: 'Listen for OSC messages to get value',
description: 'Listen for OSC messages. Requires "Listen for Feedback" option to be enabled in OSC config.',
options: [
{
type: 'textinput',
label: 'OSC Path',
id: 'path',
default: '/osc/path',
useVariables: true,
},
],
callback: async (feedback) => {
const path = optionToString(feedback.options.path);
this.log('debug', `Evaluating feedback ${feedback.id}.`);

const rx_args = this.onDataReceived[path];
return String(rx_args[0].value);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably shouldn't be blindly stringifying the value here; any json safe value is allowed. It would be good to preserve numbers.
Maybe this should check the arg type and stringify only for this which arent allowed? (some buffer/blob types probably)


},
},
});
}

updateVariables() {
this.setVariableDefinitions([
{ variableId: 'latest_received_timestamp', name: 'Latest OSC message received timestamp' },
{ variableId: 'latest_received_raw', name: 'Latest OSC message received' },
{ variableId: 'latest_received_path', name: 'Latest OSC command received' },
{ variableId: 'latest_received_client', name: 'Latest OSC message received client (UDP only)' },
{ variableId: 'latest_received_port', name: 'Latest OSC message received port (UDP only)' },
{ variableId: 'latest_received_args', name: 'Latest OSC arguments received array.' },
{ variableId: 'latest_sent_timestamp', name: 'Latest OSC message sent timestamp' },
{ variableId: 'latest_sent_raw', name: 'Latest OSC message sent' },
{ variableId: 'latest_sent_path', name: 'Latest OSC command sent' },
{ variableId: 'latest_sent_args', name: 'Latest OSC arguments sent array.' },
]);
this.setVariableDefinitions({
latest_received_timestamp: { name: 'Latest OSC message received timestamp' },
latest_received_raw: { name: 'Latest OSC message received' },
latest_received_path: { name: 'Latest OSC command received' },
latest_received_client: { name: 'Latest OSC message received client (UDP only)' },
latest_received_port: { name: 'Latest OSC message received port (UDP only)' },
latest_received_args: { name: 'Latest OSC arguments received array.' },
latest_sent_timestamp: { name: 'Latest OSC message sent timestamp' },
latest_sent_raw: { name: 'Latest OSC message sent' },
latest_sent_path: { name: 'Latest OSC command sent' },
latest_sent_args: { name: 'Latest OSC arguments sent array.' },
});
}
}

runEntrypoint(OSCInstance, UpgradeScripts);
module.exports = OSCInstance;
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "generic-osc",
"version": "2.7.0",
"version": "2.9.0",
"main": "osc.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
Expand All @@ -17,12 +17,12 @@
"node": ">=22.18.0"
},
"dependencies": {
"@companion-module/base": "1.13.6",
"@companion-module/base": "2.0.4",
"osc": "^2.4.5",
"osc-js": "^2.4.1",
"prettier": "^3.7.4"
},
"devDependencies": {
"@companion-module/tools": "^2.6.0"
"@companion-module/tools": "^3.0.1"
}
}
Loading