Hello everyone,
I came across this, working on a script that selects the next memory location by matching word on memory location name. My first version of the script, changes main counter to samples and filters memory location by name and location in samples larger than current location. So far from my test it's been reliable, you can find it here.
Identical Marker Navigation
In the mean time I made a version that doesn't have to change the main counter, it replaces any symbols separating the numbers on any time of counter and uses them as plain numbers to know witch marker is after current location.
But I'm finding different behaviours depending if I'm using memoryLocationsFetch or memoryLocationsFetchFromGui or memoryLocationsFetchFromPtx.
And weird as well in the sense, some counters work but ignore markers or stop working, but work again. But if in time code, never fails. I would expect samples not to fail, but thats not the case.
I'm hoping it has something to to with the way I'm reading the memory locations, but, so far, can't figure it out.
Any ideas?
And as always, thank you so much!!
heres the last code:
function findLocationNameMatch(locationName) {
const mainCounter = sf.ui.proTools.getCurrentTimecode().stringValue
let cleanMainCounter = mainCounter.replace(/[ :\+\|.]/g,'').trim()
// if maulter is bars beats, remove last three digits, since memory locations list ignores them
mainCounter.match(/\|/) ? cleanMainCounter = cleanMainCounter.slice(0, -3) : null
const memoryLocations = sf.proTools.memoryLocationsFetch().collection.list.filter(x =>
x.mainCounterValue.replace(/[ :\+\|.]/g,'').trim() > cleanMainCounter &&
x.name.match(locationName));
try {
sf.ui.proTools.memoryLocationsGoto({
memoryLocationNumber: memoryLocations[0].number
});
} catch (err) { log(`End of location markers containing:\n${locationName}`) }
}
sf.ui.proTools.appActivateMainWindow();
findLocationNameMatch("yadda")
Linked from:
samuel henriques @samuel_henriquesUPDATE: found some errors but didn't improve my problem. Updated script.
In reply tosamuel_henriques⬆:Kitch Membery @Kitch2021-03-18 19:02:43.339ZHi Legend!
Did you try using;
const mainCounterInSamples = sf.ui.proTools.selectionGetInSamples().selectionStart;...to get the samples?
Kitch Membery @Kitch2021-03-18 19:09:20.229ZI read your post wrong. ignore my reply above.
- In reply toKitch⬆:
samuel henriques @samuel_henriqueshey Master Kitch,
I did as well, thats how the other script is working. But I'm trying to do this without the change Main Counter step. If we remove the symbols, any counter is a number that will fine for this. Do you know how I can find the diferences between
memoryLocationsFetch,memoryLocationsFetchFromGui. andmemoryLocationsFetchFromPtx?I think I'm using the wrong one and I have some mistake on my code (probably Regex) or the order I'm doing something.
Thanks Kitch!!
Kitch Membery @Kitch2021-03-18 20:02:12.690ZI think the first two return the same object, however the "Ptx" version does not return an object for me at all.
Simply logging
log(sf.proTools.memoryLocationsFetch());should show you the differences.You can use this to see code, to see if the regex is returning the result you want..
let memoryLoactions = sf.proTools.memoryLocationsFetch().collection['list'].map(l => ({ name: l.name, joinedMainCounterReadout: l['MainCounterValue'].replace(/[ :\+\|.]/g, ''), })); log(memoryLoactions);
samuel henriques @samuel_henriquesthank you Kitch, I'll try this as well.
For the "Ptx" to get the object, you need to save the session after creating the location markers. That might be why you'r not getting anything. It took me a few hours a while ago when I first met it, changed so much code to figure what I was doing wrong before noticing, I was working on a code for someone on the forum and immediately added a save line at beginning of the script :)
Kitch Membery @Kitch2021-03-18 21:14:25.924ZAhh I see :-)
I've never used that one before, that makes complete sense.
Try aproaching it like this so you can use the original element to reselect;
function getNextMatchedMemoryLocation(name, currentLocationTime) { let memoryLoactions = sf.proTools.memoryLocationsFetch().collection['list'].map(l => ({ name: l.name, joinedMainCounterReadout: l['MainCounterValue'].replace(/[ :\+\|.]/g, ''), mainCounterValue: l })); return memoryLoactions .filter(ml => ml.name === name) .filter(ml => ml.joinedMainCounterReadout > currentLocationTime)[0]; } let nextMemoryLocation = getNextMatchedMemoryLocation('Location 1', '00000908'); log(nextMemoryLocation.mainCounterValue);Let me know if that makes sense.
Rock on!
samuel henriques @samuel_henriquesHey Kitch,
Thank you for your function, it's a bit confusing for my understanding, but it makes sense, and I managed to make it work.
It gave similar results to my previous script, witch let me to think, that it's not thememoryLocationsFetchproblem, and I changed the regex to[^0-9]witch is simpler but got me the same problems.
So I found this:let a = "2859148" let b = "122008320" log(b>a)// falsebut:
let a = "0000002859148" let b = "122008320" log(b>a) //truethis is the mf problem!!!
samuel henriques @samuel_henriquesstill....not the fix
- In reply tosamuel_henriques⬆:
Kitch Membery @Kitch2021-03-19 09:39:24.254ZHave you tried converting the strings to a number first?
let a = Number("2859148"); let b = Number("122008320"); log(b>a); //Trueand
let a = Number("0000002859148"); let b = Number("122008320"); log(b>a); //True
samuel henriques @samuel_henriquesAAAAAHHHHHHH!! That's it. You were so fast I thought there should be a javascript method to fix this and was looking for this solution!!
Thank you so much Master Kitch.I think I'm only one step away to get this script right.
Kitch Membery @Kitch2021-03-19 09:56:19.949ZAwesome!!
There are many little things like this that once you deal with it once you never forget again :-)
Love your work, Samuel!
Rock on
- In reply toKitch⬆:
Chris Shaw @Chris_Shaw2021-03-19 15:28:53.158ZJust to chime in here:
You can also use+instead ofNumber
So instead of:let a = Number("0000002859148"); let b = Number("122008320");You can use:
let a = +("0000002859148"); let b = +("122008320");or
let a = +"0000002859148"; let b = +"122008320"; log(b>a);
Chris Shaw @Chris_Shaw2021-03-19 15:36:31.242ZKeep In mind if you want to add the converted string to an existing number you have to use two
+symbols…This combines the two numbers and returns a string
let b = 1+("122008320"); log(b);// result 1122008320 (Combines and returns a new string. (note the additional "1" at the beginning of result)this adds the two numbers
let b = 1+ +("122008320"); log(b);// result - 122008321. The numbers have been added together
samuel henriques @samuel_henriquesnice one,
thank you @Chris_Shaw