Skip to content

Commit

Permalink
Save in worker when channel moved
Browse files Browse the repository at this point in the history
  • Loading branch information
mamarguerat committed Jul 2, 2024
1 parent bff60ee commit fdee85f
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/js/beans/channel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Channel {
constructor(id) {
this._id = id;
constructor() {
this._deviceId = "";
this._IO = "";
this._source = "";
Expand Down
42 changes: 37 additions & 5 deletions src/js/beans/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ class Device {
}
// Create array of channels
for (let i = 0; i < totalChannels; i++) {
this.channels.push(new Channel(i));
this.channels.push(new Channel());
}
// Create array of mixbuses
for (let i = 0; i < totalMixbuses; i++) {
this.mixbuses.push(new Channel(i));
this.mixbuses.push(new Channel());
}
// Create array of matrix
for (let i = 0; i < totalMatrix; i++) {
this.matrix.push(new Channel(i));
this.matrix.push(new Channel());
}
// Create array of stereo
for (let i = 0; i < totalStereo; i++) {
this.stereo.push(new Channel(i));
this.stereo.push(new Channel());
}
// Create array of dca
for (let i = 0; i < totalDca; i++) {
this.dca.push(new Channel(i));
this.dca.push(new Channel());
}
}

Expand Down Expand Up @@ -84,4 +84,36 @@ class Device {
getName() {
return this.name;
}

// MARK: Public functions
moveChannel(channelType, fromIndex, toIndex) {
if (channelType == "input") {
this.channels = array_move(this.channels, fromIndex, toIndex);
}
else if (channelType == "mixbus") {
this.mixbuses = array_move(this.mixbuses, fromIndex, toIndex);
}
else if (channelType == "matrix") {
this.matrix = array_move(this.matrix, fromIndex, toIndex);
}
else if (channelType == "stereo") {
this.stereo = array_move(this.stereo, fromIndex, toIndex);
}
else if (channelType == "dca") {
this.dca = array_move(this.dca, fromIndex, toIndex);
}
}
}

// MARK: Private funcitons
/*----- Private functions ---------------------------------------------------------------------------------------------------*/
function array_move(arr, old_index, new_index) {
if (new_index >= arr.length) {
var k = new_index - arr.length + 1;
while (k--) {
arr.push(undefined);
}
}
arr.splice(new_index, 0, arr.splice(old_index, 1)[0]);
return arr;
};
10 changes: 5 additions & 5 deletions src/js/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,35 +65,35 @@ class Const {
ret.devices[devIdx].outputs[connIdx]._icon = output._icon;
});
device.channels.forEach(channel => {
ret.devices[devIdx].channels.push(new Channel(channel._id));
ret.devices[devIdx].channels.push(new Channel());
var chIdx = ret.devices[devIdx].channels.length - 1;
ret.devices[devIdx].channels[chIdx]._deviceId = channel._deviceId;
ret.devices[devIdx].channels[chIdx]._IO = channel._IO;
ret.devices[devIdx].channels[chIdx]._source = channel._source;
})
device.mixbuses.forEach(mixbus => {
ret.devices[devIdx].mixbuses.push(new Channel(mixbus._id));
ret.devices[devIdx].mixbuses.push(new Channel());
var chIdx = ret.devices[devIdx].mixbuses.length - 1;
ret.devices[devIdx].mixbuses[chIdx]._deviceId = mixbus._deviceId;
ret.devices[devIdx].mixbuses[chIdx]._IO = mixbus._IO;
ret.devices[devIdx].mixbuses[chIdx]._source = mixbus._source;
})
device.matrix.forEach(matrix => {
ret.devices[devIdx].matrix.push(new Channel(matrix._id));
ret.devices[devIdx].matrix.push(new Channel());
var chIdx = ret.devices[devIdx].matrix.length - 1;
ret.devices[devIdx].matrix[chIdx]._deviceId = matrix._deviceId;
ret.devices[devIdx].matrix[chIdx]._IO = matrix._IO;
ret.devices[devIdx].matrix[chIdx]._source = matrix._source;
})
device.stereo.forEach(stereo => {
ret.devices[devIdx].stereo.push(new Channel(stereo._id));
ret.devices[devIdx].stereo.push(new Channel());
var chIdx = ret.devices[devIdx].stereo.length - 1;
ret.devices[devIdx].stereo[chIdx]._deviceId = stereo._deviceId;
ret.devices[devIdx].stereo[chIdx]._IO = stereo._IO;
ret.devices[devIdx].stereo[chIdx]._source = stereo._source;
})
device.dca.forEach(dca => {
ret.devices[devIdx].dca.push(new Channel(dca._id));
ret.devices[devIdx].dca.push(new Channel());
var chIdx = ret.devices[devIdx].dca.length - 1;
ret.devices[devIdx].dca[chIdx]._deviceId = dca._deviceId;
ret.devices[devIdx].dca[chIdx]._IO = dca._IO;
Expand Down
26 changes: 23 additions & 3 deletions src/js/ctrl/deviceDetailCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ class DeviceDetailCtrl {
});
}

/**
* Channel position changed
*/
moveChannel() {
ipcRenderer.send('forward-to-main', { worker: indexWrk });
}

/**
* Save button pressed
*/
Expand Down Expand Up @@ -322,6 +329,14 @@ class DeviceDetailCtrl {
console.error(`[deviceDetailCtrl] Error fetching the SVG file ${error}`);
});
}
else {
$element.eq(index).children("div").children("p").text("NO IO SELECTED");
$element.eq(index).children("div").css("background-color", "#999999");
$element.eq(index).children("div").css("color", "#000000");
$element.eq(index).children("div").css("border", "none");
$element.eq(index).children("p").text("");
$element.eq(index).children("div").children("svg").empty();
}
});
}

Expand All @@ -336,7 +351,7 @@ class DeviceDetailCtrl {
// Create sortables
for (var i = 0; i < channelCnt; i++) {
$('#' + id + '-channel-names').append("<div class='channel-name'>" + channelName + " " + (i+1) + "</div>");
$('#' + id + '-sortable').append("<div class='io-element'><div style='background-color: #999999;'><p>NO IO SELECTED</p><svg height='40px' width='50px'></svg></div><p>LOCAL " + (i+1) + "</p></div>");
$('#' + id + '-sortable').append("<div class='io-element'><div style='background-color: #999999;'><p>NO IO SELECTED</p><svg height='40px' width='50px'></svg></div><p></p></div>");
}
$('#' + id + '-sortable').sortable({
multiDrag: false,
Expand All @@ -348,10 +363,15 @@ class DeviceDetailCtrl {
});

var _this = this;
$('#' + id + '-sortable').on("end", function (ev) {
indexWrk.moveChannel(_this.deviceID, "input", ev.originalEvent.oldIndex, ev.originalEvent.newIndex);
_this.moveChannel();
});

$('.io-element').on("click", function (ev) {
_this.selectedChannel = 1;
_this.openChannelModal();
})
});
}
}

Expand Down Expand Up @@ -446,4 +466,4 @@ class DeviceDetailCtrl {
$btn.prepend($text[0].outerHTML);
$btn.prepend($icon[0].outerHTML);
}
}
}
2 changes: 1 addition & 1 deletion src/js/ctrl/indexCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class IndexCtrl {
if ('save' == arg.function || 'saveas' == arg.function) {
console.log(`[indexCtrl] save file`);
// Convert the object to JSON
let json = JSON.stringify(indexWrk, null, 2);
let json = JSON.stringify(indexWrk, null, 0);
ipcRenderer.send('file', {
function: arg.function,
json: json
Expand Down
3 changes: 3 additions & 0 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ ipcMain.on('window', (event, arg) => {
});

ipcMain.on('file', (event, arg) => {
let jsonObject = JSON.parse(arg.json);
jsonObject.version = app.getVersion();
arg.json = JSON.stringify(jsonObject, null, 2);
if ('saveas' == arg.function || ('save' == arg.function && filePath == "")) {
dialog.showSaveDialog({
title: 'Save Mixo project',
Expand Down
12 changes: 12 additions & 0 deletions src/js/wrk/indexWrk.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,18 @@ class IndexWrk {
return device.outputs[index];
}
}

/**
* Move a channel from index to index
* @param {Number} deviceID
* @param {String} channelType
* @param {Number} fromIndex
* @param {Number} toIndex
*/
moveChannel(deviceID, channelType, fromIndex, toIndex) {
console.log(`[indexWrk] Move channel ${channelType} from ${fromIndex} to ${toIndex}`);
this.devices[id2index(deviceID, this.devices)].moveChannel(channelType, fromIndex, toIndex);
}
}

// MARK: Private funcitons
Expand Down

0 comments on commit fdee85f

Please sign in to comment.