|
|
|
08-01-2015, 07:08 AM
|
#1
|
Human being with feelings
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,984
|
Lua: Create Snap Offset at maximum peak in first second of take
Hi, guys.
I wrote a script to automatically create Snap Offset on maximum peak value on first second of take. Seem to be something wrong with audioaccessor (sometimes changing item selection does not affect to values, like REAPER leave last used accessor in the memory and didnt get new accessor). Sometimes it works, sometimes not, don`t know why. Can anyone confirm is it works or not? And if not, where I was wrong?
PHP Code:
item = reaper.GetSelectedMediaItem(0, 0) take = reaper.GetActiveTake(item) source = reaper.GetMediaItemTake_Source(take)
accessor = reaper.CreateTakeAudioAccessor(take) samplerate = reaper.GetMediaSourceSampleRate(source) channels = reaper.GetMediaSourceNumChannels(source) start_pos = 0 samples = samplerate buf_size = samples -- first 1 second buffer = reaper.new_array(buf_size*channels)
reaper.GetAudioAccessorSamples(accessor, samplerate, channels, start_pos, samples, buffer)
sample_max = 0 for i = 1, buf_size do sample = math.abs(buffer[i]) sample_max = math.max(sample, sample_max) if sample_max ~= sample_max0 -- if max peak value is changed then max_peak_sample = i/channels end sample_max0 = sample_max end
snap_offset_position = max_peak_sample / samplerate reaper.DestroyAudioAccessor(accessor) reaper.SetMediaItemInfo_Value(item, "D_SNAPOFFSET", snap_offset_position) reaper.UpdateArrange()
Last edited by mpl; 08-01-2015 at 07:17 AM.
|
|
|
08-01-2015, 10:12 AM
|
#2
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Hi,
It seems to work here (if a take source has 1 channel).
|
|
|
08-01-2015, 11:14 AM
|
#3
|
Human being with feelings
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,984
|
Strange... Sometimes buffer return extremely small values, even if i don't change code and just run script again.
I understood that samples going to buffer from same position one channel after another, so i put
PHP Code:
max_peak_sample = i/channels
.
But I have a feel something wrong here (or there is a deep bug in accessor api not reproducible simply).
|
|
|
03-28-2020, 11:41 AM
|
#4
|
Human being with feelings
Join Date: Mar 2015
Posts: 29
|
Very useful script, thanks mpl!
Is it possible to set the snap offset at the peak of the entire file instead of the first second?
Also the script only sets the snap offset to the first of the selected files. It would be great to be able to do that for all the selected files at once.
|
|
|
04-21-2020, 01:56 PM
|
#5
|
Human being with feelings
Join Date: Mar 2013
Posts: 131
|
Quote:
Originally Posted by alex_
Very useful script, thanks mpl!
Is it possible to set the snap offset at the peak of the entire file instead of the first second?
Also the script only sets the snap offset to the first of the selected files. It would be great to be able to do that for all the selected files at once.
|
I am interested as well in this behaviour, please!
|
|
|
04-21-2020, 03:03 PM
|
#6
|
Human being with feelings
Join Date: May 2019
Location: Los Angeles, CA
Posts: 161
|
Quote:
Originally Posted by vala
I am interested as well in this behaviour, please!
|
If you don't need the 1 sec time constraint, there are built-in Actions (via SWS) that will do this:
SWS: Move cursor to item peak sample
-then-
Item: Set snap offset to cursor
Combine those two into a Custom Action. I have one that I constantly use for this very application.
If you don't want the cursor to move, run these at the start/end of the Action, respectively, and it will appear that the cursor never moved:
SWS/BR: Save edit cursor position, slot 01
SWS/BR: Restore edit cursor position, slot 01
|
|
|
04-21-2020, 03:44 PM
|
#7
|
Human being with feelings
Join Date: Mar 2013
Posts: 131
|
@TabbyCat:
oh yes, lovely! thank you!
|
|
|
05-12-2020, 12:12 PM
|
#8
|
Human being with feelings
Join Date: Mar 2015
Posts: 29
|
great, thanks
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 03:55 PM.
|