Skip to content

Commit

Permalink
simplify and support grouped tracks on the group parent
Browse files Browse the repository at this point in the history
  • Loading branch information
zsteinkamp committed Apr 27, 2024
1 parent 7f01404 commit 9227485
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 31 deletions.
Binary file modified ChiasticSlide.amxd
Binary file not shown.
109 changes: 78 additions & 31 deletions chiasticSlide.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
autowatch = 1
var MAX_PARAMS = 32
inlets = 1
outlets = MAX_PARAMS + 1
outlets = 3

var debugLog = true

setinletassist(0, '<Bang> to initialize, <Float> to fade.')
setoutletassist(0, '<String> Status message to display.')
OUTLET_STATUS = 0

var debugLog = false
OUTLET_VAL = 1
OUTLET_IDS = 2
setoutletassist(OUTLET_STATUS, '<String> Status message to display.')
setoutletassist(OUTLET_VAL, '<chain idx, val> Volume value for given chain.')
setoutletassist(
OUTLET_IDS,
'<chain idx, id, param_id> messages to map live.remote to device id param_id.'
)

function debug() {
if (debugLog) {
Expand All @@ -26,7 +33,7 @@ var state = {
val: 0,
width: 2,
numChains: 0,
//chains: [],
chains: [],
}

function bang() {
Expand Down Expand Up @@ -56,11 +63,11 @@ function updateVolumes() {
var tolerance = chainTurf * state.width
if (distanceToNumber > tolerance) {
//debug('VOLVAL ' + i + ' ZERO')
outlet(i + 1, 0.0)
outlet(OUTLET_VAL, [i + 1, 0.0])
} else {
var newVol = (1.0 - distanceToNumber / tolerance) * 0.85
//debug('VOLVAL ' + i + ' ' + newVol)
outlet(i + 1, newVol)
outlet(OUTLET_VAL, [i + 1, newVol])
}
}
}
Expand All @@ -69,15 +76,10 @@ function sendStatus(str) {
outlet(OUTLET_STATUS, str)
}

function initialize() {
debug('INITIALIZE')
var thisDevice = new LiveAPI('live_set this_device')
function getRackDevicePaths(thisDevice, volumeDevicePaths) {
var thisDevicePathTokens = thisDevice.unquotedpath.split(' ')
if (thisDevicePathTokens.length != 5) {
sendStatus('ERROR: invalid path ' + thisDevicePathTokens.join(','))
return
}
var thisDeviceNum = parseInt(thisDevicePathTokens[4])
var tokenLen = thisDevicePathTokens.length
var thisDeviceNum = parseInt(thisDevicePathTokens[tokenLen - 1])

if (isNaN(thisDeviceNum)) {
sendStatus('ERROR: NaN device num :(')
Expand All @@ -91,7 +93,9 @@ function initialize() {
//debug('DEVICENUM = ' + thisDeviceNum)

var prevDevicePath =
thisDevicePathTokens.slice(0, 4).join(' ') + ' ' + (thisDeviceNum - 1)
thisDevicePathTokens.slice(0, tokenLen - 1).join(' ') +
' ' +
(thisDeviceNum - 1)
//debug('PREVDEVICEPATH=' + prevDevicePath)

var prevDevice = new LiveAPI(prevDevicePath)
Expand All @@ -100,35 +104,78 @@ function initialize() {
return
}

var jsObj = this.patcher.getnamed('jsObj')
var liveApi = new LiveAPI()
var currChain
for (currChain = 0; currChain < MAX_PARAMS; currChain++) {
var currChainPath =
prevDevicePath + ' chains ' + currChain + ' mixer_device volume'
//debug('CURR_CHAIN_PATH=' + currChainPath)

liveApi.path = currChainPath
if (!liveApi.path) {
//debug('last one okay!')
return
}
volumeDevicePaths.push(currChainPath)
}
}

function getGroupTrackPaths(thisDevice, volumeDevicePaths) {
var thisTrack = new LiveAPI(thisDevice.get('canonical_parent'))
if (thisTrack.get('is_foldable')) {
// THIS IS A GROUP TRACK
//debug('GROUP TRACK')
var api = new LiveAPI(this.patcher, 'live_set')
var trackCount = api.getcount('tracks')
//debug('THIS TRACK', thisTrack.id)

for (var index = 0; index < trackCount; index++) {
api.path = 'live_set tracks ' + index
//debug(api.path)
if (parseInt(api.get('group_track')[1]) === parseInt(thisTrack.id)) {
volumeDevicePaths.push(api.unquotedpath + ' mixer_device volume')
//debug('FOUND CHILD', api.id, api.unquotedpath + ' mixer_device volume')
}
}
}
}

function initialize() {
debug('INITIALIZE')
var thisDevice = new LiveAPI('live_set this_device')

// populate volumeDevicePaths either from a rack device (instrument or effect)
// or as the parent of a track group
var volumeDevicePaths = []
getRackDevicePaths(thisDevice, volumeDevicePaths)
if (volumeDevicePaths.length === 0) {
getGroupTrackPaths(thisDevice, volumeDevicePaths)
}

// properly let go of devices for existing live.remote~ objects
for (var i = 0; i < MAX_PARAMS; i++) {
outlet(i + 1, ['id', 0])
outlet(OUTLET_IDS, [i + 1, 'id', 0])
//debug('REMOVED ' + (i + 1))
}

var currChain = 0
while (currChain < MAX_PARAMS) {
var currChainPath =
prevDevicePath + ' chains ' + currChain + ' mixer_device volume'
//debug('CURR_CHAIN_PATH=' + currChainPath)

var chainDeviceVolumeParam = new LiveAPI(currChainPath)
if (!chainDeviceVolumeParam.path) {
//debug('last one okay!')
var lookupApi = new LiveAPI()
var currChain
for (currChain = 0; currChain < volumeDevicePaths.length; currChain++) {
var currChainPath = volumeDevicePaths[currChain]
lookupApi.path = currChainPath
if (!lookupApi.path) {
debug('last one okay!')
break
}
var deviceParamId = parseInt(chainDeviceVolumeParam.id)
var deviceParamId = parseInt(lookupApi.id)
debug('PARAM_ID: ' + deviceParamId)
outlet(currChain + 1, ['id', deviceParamId])
currChain += 1
outlet(OUTLET_IDS, [currChain + 1, 'id', deviceParamId])
}

if (currChain > 0) {
sendStatus('OK - Set up ' + currChain + ' chains.')
} else {
sendStatus('ERROR: Not a rack to my left.')
sendStatus('ERROR: Cannot handle it.')
}
state.numChains = currChain
updateVolumes()
Expand Down
114 changes: 114 additions & 0 deletions remote.maxpat
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
"patcher" : {
"fileversion" : 1,
"appversion" : {
"major" : 8,
"minor" : 6,
"revision" : 0,
"architecture" : "x64",
"modernui" : 1
}
,
"classnamespace" : "box",
"rect" : [ 136.0, 521.0, 640.0, 480.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
"default_fontface" : 0,
"default_fontname" : "Arial",
"gridonopen" : 1,
"gridsize" : [ 15.0, 15.0 ],
"gridsnaponopen" : 1,
"objectsnaponopen" : 1,
"statusbarvisible" : 2,
"toolbarvisible" : 1,
"lefttoolbarpinned" : 0,
"toptoolbarpinned" : 0,
"righttoolbarpinned" : 0,
"bottomtoolbarpinned" : 0,
"toolbars_unpinned_last_save" : 0,
"tallnewobj" : 0,
"boxanimatetime" : 200,
"enablehscroll" : 1,
"enablevscroll" : 1,
"devicewidth" : 0.0,
"description" : "",
"digest" : "",
"tags" : "",
"style" : "",
"subpatcher_template" : "",
"assistshowspatchername" : 0,
"boxes" : [ {
"box" : {
"id" : "obj-3",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 171.0, 80.0, 28.0, 22.0 ],
"saved_object_attributes" : {
"attr_comment" : ""
}
,
"text" : "in 1"
}

}
, {
"box" : {
"id" : "obj-2",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 218.0, 185.0, 99.0, 22.0 ],
"text" : "print #0---FOO"
}

}
, {
"box" : {
"id" : "obj-43",
"maxclass" : "newobj",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 171.0, 258.0, 74.0, 22.0 ],
"saved_object_attributes" : {
"_persistence" : 1,
"normalized" : 0,
"smoothing" : 1.0
}
,
"text" : "live.remote~",
"varname" : "remote0[6]"
}

}
],
"lines" : [ {
"patchline" : {
"destination" : [ "obj-2", 0 ],
"order" : 0,
"source" : [ "obj-3", 0 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-43", 0 ],
"order" : 1,
"source" : [ "obj-3", 0 ]
}

}
],
"saved_attribute_attributes" : {
"default_plcolor" : {
"expression" : ""
}

}

}

}

0 comments on commit 9227485

Please sign in to comment.