|
|
|
02-24-2017, 07:02 PM
|
#1
|
Human being with feelings
Join Date: Aug 2012
Posts: 271
|
Lua: New Function - GetMediaItemTake_Peaks
We are now able to use this?
It definitely will not be changed?
=============
Example:
Code:
min_freq = 80
max_freq = 1000
Thresh_dB = -40
min_tonal = 0.85
------------------------------------------------------------
function Init()
-- Some gfx Wnd Default Values ---------------
local Wnd_bgd = 0x0F0F0F
local Wnd_Title = "Test"
local Wnd_Dock,Wnd_X,Wnd_Y = 0,100,320
Wnd_W,Wnd_H = 1044,490 -- global values(used for define zoom level)
-- Init window ------
gfx.clear = Wnd_bgd
gfx.init( Wnd_Title, Wnd_W,Wnd_H, Wnd_Dock, Wnd_X,Wnd_Y )
end
------------------------------------------------------------
function Peaks_Draw(Peaks)
local min_note = 69 + 12 * math.log(min_freq/440, 2)
local max_note = 69 + 12 * math.log(max_freq/440, 2)
local Thresh = 10 ^ (Thresh_dB/20)
----------------------
local axis = gfx.h * 0.5
local Ky = gfx.h * 0.5
local Kn = gfx.h/(max_note-min_note)
local offs = min_note * Kn
----------------------
local abs, max = math.abs, math.max
for i = 1, #Peaks, 4 do
local max_peak, min_peak = Peaks[i], Peaks[i+1]
local xx = i/4
gfx.set(0,0.5,0,1)
gfx.line(xx , axis - max_peak*Ky, xx, axis - min_peak*Ky, true) -- Peaks
--------------------
if max(abs(max_peak), abs(min_peak)) > Thresh then
local freq, tonal = Peaks[i+2], Peaks[i+3]
local note = 69 + 12 * math.log(freq/440, 2)
if tonal >= min_tonal and note >= min_note and note <= max_note then
gfx.x = xx; gfx.y = gfx.h + offs - note*Kn;
gfx.setpixel(1,0,0)
elseif note < min_note then
gfx.x = xx; gfx.y = gfx.h - 10;
gfx.setpixel(0,0,1)
elseif note > max_note then
gfx.x = xx; gfx.y = 10;
gfx.setpixel(0,1,1)
end
end
end
end
------------------------------------------------------------
function Item_GetPeaks(item)
if not item then return end
local take = reaper.GetActiveTake(item)
if not take or reaper.TakeIsMIDI(take) then return end
local item_start = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
local item_len = reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
local sel_start, sel_end = reaper.GetSet_LoopTimeRange(false, false, 0, 0, false)
if sel_end - sel_start == 0 then sel_start = item_start; sel_end = item_start + item_len end
local starttime = math.max(sel_start, item_start)
local len = math.min(sel_end, item_start + item_len) - starttime
if len <= 0 then return end
------------------
--PCM_Source = reaper.GetMediaItemTake_Source(take)
local n_chans = 1 -- I GetPeaks Only from 1 channel!!!
local peakrate = gfx.w / len
local n_spls = math.floor(len*peakrate + 0.5) -- its Peak Samples
local want_extra_type = 115 -- 's' char
local buf = reaper.new_array(n_spls * n_chans * 3) -- max, min, spectral each chan(but now 1 chan only)
buf.clear() -- Clear buffer
------------------
local retval = reaper.GetMediaItemTake_Peaks(take, peakrate, starttime, n_chans, n_spls, want_extra_type, buf);
local spl_cnt = (retval & 0xfffff) -- sample_count
local ext_type = (retval & 0x1000000)>>24 -- extra_type was available
local out_mode = (retval & 0xf00000)>>20 -- output_mode
------------------
local Peaks = {}
if spl_cnt > 0 and ext_type > 0 then
for i = 1, n_spls do
local p = #Peaks
Peaks[p+1] = buf[i] -- max peak
Peaks[p+2] = buf[n_spls + i] -- min peak
--------------
local spectral = buf[n_spls*2 + i] -- spectral peak
-- freq and tonality from spectral peak --
Peaks[p+3] = spectral&0x7fff -- low 15 bits frequency
Peaks[p+4] = (spectral>>15)/16384 -- tonality norm value
end
end
------------------
return Peaks
end
---------------------------
function Project_IsChanged()
local cur_cnt = reaper.GetProjectStateChangeCount(0)
if cur_cnt ~= proj_change_cnt then proj_change_cnt = cur_cnt
return true
end
end
---------------------------
function main()
if Project_IsChanged() then
gfx.setimgdim(0, 0, 0) -- clear buf 0
gfx.setimgdim(0, gfx.w, gfx.h)
gfx.dest = 0; -- set dest buf = 0
local item = reaper.GetSelectedMediaItem(0, 0)
if item then
local Peaks = Item_GetPeaks(item)
if Peaks then Peaks_Draw(Peaks) end
end
end
-----------
local img_w, img_h = gfx.getimgdim(0)
if img_w > 0 and img_h > 0 then
gfx.a = 1; gfx.dest = -1; gfx.x, gfx.y = 0, 0
gfx.blit(image, 1, 0, 0, 0, img_w, img_h, 0, 0, gfx.w, gfx.h)
end
-----------
char = gfx.getchar()
if char == 32 then reaper.Main_OnCommand(40044, 0) end -- play
if char ~= -1 then reaper.defer(main) end -- defer
-----------
gfx.update()
-----------
end
Init()
main()
Last edited by eugen2777; 11-08-2017 at 10:12 AM.
|
|
|
02-25-2017, 07:39 AM
|
#2
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,599
|
Hi eugen,sorry for offtopic but you got something I really need for a long time. I've modified the script a little to act the way I need but:
How can I draw edit cursor here so it replicates the position from arrange?
I need this "Editing Guide" when editing tracks that are bellow or in the middle of the project and I cannot see the source track. The script needs to "Lock Waveform of selected track" so here is a little gif.
Lets say I've locked the first track "Kick" as GUIDE track, now that waveform stays in the script so I can see it as I edit another track. But I need edit cursor position also to be drawed so I know how much I need to offset the new edit. Hope this makes sence.
Now I only need to see edit cursor too in the script
In your script I only modified the start-end to be arrange window rather than time selection
Code:
sel_start, sel_end = reaper.BR_GetArrangeView(0)
I did not included or coded Lock track yet
Here is the mockup what I need :
Thank you very much!
Last edited by Sexan; 02-25-2017 at 07:50 AM.
|
|
|
02-26-2017, 07:18 AM
|
#3
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,599
|
It can be EXTREMELY efficient when optimized even at much higher resolutions by dinamically altering it based on zoom level
|
|
|
02-26-2017, 10:10 AM
|
#4
|
Human being with feelings
Join Date: Aug 2012
Posts: 271
|
Yes, it is very fast, it was just a simple example.
Specifically, as to make it easier.
And do not forget, pay attention to the frequency of the, it's more fun
|
|
|
02-26-2017, 10:28 AM
|
#5
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,599
|
Sorry for writing off topic here,this is the first simple script for waveforms so I've finally learned something about it, thank you very much!
I've removed "not-necessary" code from it to adjust it to my needs (a very very simple waveform viewer),but I have one issue that I do not know yet how to fix
https://dl.dropboxusercontent.com/u/...dification.lua
At the end of the item weird jiterring begins :
I assume its because there are no more samples at the end so it freaks out like this
And please can you show me how to draw edit cursor in the script (never done that before)?
Once again thank you very much!
Quote:
Originally Posted by eugen2777
And do not forget, pay attention to the frequency of the, it's more fun
|
I think I've removed that from the code if you mean "frequency = spec&0x7fff"
|
|
|
02-26-2017, 12:38 PM
|
#6
|
Human being with feelings
Join Date: Aug 2012
Posts: 271
|
Well, I'll look at it tomorrow, I have no time now!
This will be decided!
|
|
|
02-27-2017, 05:31 AM
|
#8
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,599
|
Yeah! I've requested this script few times but noone responded.Thanks for snippet
|
|
|
03-12-2017, 02:12 AM
|
#9
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,599
|
I need to bump this, I need edit cursor position in here but I'm mathematically challenged for that kind of procedure. I managed to render it but its way of the possition
Last edited by Sexan; 03-12-2017 at 02:19 AM.
|
|
|
09-28-2018, 06:05 AM
|
#10
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
Maybe this could be mod to handle my Faint Peak - Overlapping Items FR in some ways . Not as handy as native solution though...
(also, was there any other simple items to waveform gfx script ?)
|
|
|
09-28-2018, 06:30 AM
|
#11
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
Here is a small demo:
(thx Eugen for the initial code snippet !)
|
|
|
09-29-2018, 07:48 AM
|
#12
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,599
|
OMG Cant wait!!!!!! This will be perfect for aligning tracks that are not in the view! Thank you!
|
|
|
09-30-2018, 02:45 AM
|
#13
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
Still experimenting:
- take color
- works with selected tracks instead
- Vertical scale zoom (not shown in demo)
Aligning items at sample level precision seems prety handy with that
Note: sub sample positining isn't necessary. Rendered items with less than one sample shift results in exact same file.
Last edited by X-Raym; 09-30-2018 at 04:26 PM.
|
|
|
09-30-2018, 04:40 PM
|
#14
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
- edit cursor and play cursor
- filled waveform
- (not new but out of the box: all item waveform modifications are supported - fades, envelopes, rates)
|
|
|
09-30-2018, 04:47 PM
|
#15
|
Human being with feelings
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
|
Quote:
Originally Posted by X-Raym
- edit cursor and play cursor
- filled waveform
- (not new but out of the box: all item waveform modifications are supported - fades, envelopes, rates)
|
Very slick mon ami!!
__________________
Cheers... Andrew K
Reaper v6.80+dev0621 - June 21 2023 • Catalina • Mac Mini 2020 6 core i7 • 64GB RAM • OS: Catalina • 4K monitor • RME RayDAT card with Sync Card and extended Light Pipe.
|
|
|
10-01-2018, 03:32 AM
|
#16
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
New features:
- Track locking
- Get child track
- Arrange view width matching (manual offset for now)
- Better colors
- Vertical indicators (edit, play, time selection)
Pretty nice when it's docked above or below the arrange view :P
@Thonex
Thx :P
|
|
|
10-01-2018, 03:55 AM
|
#17
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
And now with blend mode additive switch:
|
|
|
10-01-2018, 07:14 AM
|
#18
|
Human being with feelings
Join Date: Feb 2017
Posts: 305
|
ça a l'air génial!)
|
|
|
10-02-2018, 05:11 AM
|
#19
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
|
Awesome.
|
|
|
11-11-2018, 08:56 AM
|
#20
|
Human being with feelings
Join Date: Feb 2017
Posts: 305
|
X-Raym, how is it going?
|
|
|
11-11-2018, 09:08 AM
|
#21
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
@Ivannn Bennnettt
I'm thinking about a mode which woul sum the waveform, I think it could be interesting for alignement, or null test without having to listen :P
But this need some rewriting.
|
|
|
11-11-2018, 09:38 AM
|
#22
|
Human being with feelings
Join Date: Feb 2017
Posts: 305
|
It'll be great!
Looking forward!
|
|
|
11-11-2018, 03:22 PM
|
#23
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
Here is how waveform sum could looks like:
Unfortunatly, this is not really usable for now, there is some rounding issue I don't know how to fiw which makes opposite pahse items not null when arrange view is zoom out :S
EDIT: I think I know the issue, here is the thread: https://forum.cockos.com/showthread.php?t=213286
Last edited by X-Raym; 11-11-2018 at 04:31 PM.
|
|
|
11-11-2018, 07:47 PM
|
#24
|
Human being with feelings
Join Date: Sep 2018
Location: China
Posts: 565
|
Quote:
Originally Posted by X-Raym
Here is how waveform sum could looks like:
Unfortunatly, this is not really usable for now, there is some rounding issue I don't know how to fiw which makes opposite pahse items not null when arrange view is zoom out :S
EDIT: I think I know the issue, here is the thread: https://forum.cockos.com/showthread.php?t=213286
|
What an amazing script! Is there any demo for trial?
|
|
|
11-11-2018, 09:29 PM
|
#25
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
@dysrock
Thx !
No release plan yet, just experipentation, and feedback reception on different concepts tested :P
|
|
|
11-12-2018, 07:21 AM
|
#26
|
Human being with feelings
Join Date: Feb 2017
Posts: 305
|
You're teasing and teasing
|
|
|
11-22-2018, 08:33 AM
|
#27
|
Human being with feelings
Join Date: Mar 2017
Location: Berlin
Posts: 151
|
I want this so bad!
|
|
|
12-19-2018, 04:42 PM
|
#28
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
I'm using this script right now in a project and I have to admit it is really really handy for alignong samples which are far apart on the project ! Awesome !
A bit CPU intensive if you monitor a lot of track though (like 15) but usable.
For public release, it would still need button I think.
--
I made another epxeriment based on the code, but with source peaks with time:
The idea is to visually display what section of a source the item use, and even show the overlapps of sections usage if multiple items with same section selected.
It's a bit rough for public release though, it doesn't support take rate, stretch markers, loops, section etc, it is just the basic I needed (take start offset and item length, all the rest is standard).
Very useful if you want to check that you didn't use the same pieces of audio of a soundtrack too many times !
(I made a script for that, one of my early scripts, https://forum.cockos.com/showthread.php?p=1481447 but I think it is a bit broken, and less handy than real time preview)
|
|
|
12-19-2018, 04:59 PM
|
#29
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,451
|
Quote:
Originally Posted by X-Raym
Here is how waveform sum could looks like:
|
This is amazing! Could we test it?
|
|
|
12-19-2018, 10:23 PM
|
#30
|
Human being with feelings
Join Date: Feb 2017
Posts: 305
|
still looking forward
|
|
|
01-02-2019, 02:28 AM
|
#31
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
Anyone would know how to make eugen code display multichannel ?
I tried to mod it without success so far:
Code:
min_freq = 80
max_freq = 1000
Thresh_dB = -40
min_tonal = 0.85
------------------------------------------------------------
function Init()
-- Some gfx Wnd Default Values ---------------
local Wnd_bgd = 0x0F0F0F
local Wnd_Title = "Test"
local Wnd_Dock,Wnd_X,Wnd_Y = 0,100,320
Wnd_W,Wnd_H = 1044,490 -- global values(used for define zoom level)
-- Init window ------
gfx.clear = Wnd_bgd
gfx.init( Wnd_Title, Wnd_W,Wnd_H, Wnd_Dock, Wnd_X,Wnd_Y )
end
------------------------------------------------------------
function Peaks_Draw(Peaks)
local min_note = 69 + 12 * math.log(min_freq/440, 2)
local max_note = 69 + 12 * math.log(max_freq/440, 2)
local Thresh = 10 ^ (Thresh_dB/20)
----------------------
local axis = gfx.h * 0.25
local Ky =axis
local axis2 = gfx.h * 0.75
local Ky2 = axis2
----------------------
local abs, max = math.abs, math.max
local j = 0
for i = 1, #Peaks, 8 do
j = j + 1
local max_peak, min_peak = Peaks[i], Peaks[i+2]
local xx = i/4
gfx.set(0,0.5,0,1)
if j % 2 == 0 then
gfx.line(xx , axis - max_peak*Ky, xx, axis - min_peak*Ky, true) -- Peaks
else
gfx.line(xx , axis2 - max_peak*Ky2, xx, axis2 - min_peak*Ky2, true) -- Peaks
end
end
end
------------------------------------------------------------
function Item_GetPeaks(item)
if not item then return end
local take = reaper.GetActiveTake(item)
if not take or reaper.TakeIsMIDI(take) then return end
local item_start = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
local item_len = reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
local sel_start, sel_end = reaper.GetSet_LoopTimeRange(false, false, 0, 0, false)
if sel_end - sel_start == 0 then sel_start = item_start; sel_end = item_start + item_len end
local starttime = math.max(sel_start, item_start)
local len = math.min(sel_end, item_start + item_len) - starttime
if len <= 0 then return end
------------------
--PCM_Source = reaper.GetMediaItemTake_Source(take)
local n_chans = 2 -- I GetPeaks Only from 1 channel!!!
local peakrate = gfx.w / len
local n_spls = math.floor(len*peakrate + 0.5) * n_chans -- its Peak Samples
local want_extra_type = 115 -- 's' char
local buf = reaper.new_array(n_spls * n_chans * 3) -- max, min, spectral each chan(but now 1 chan only)
buf.clear() -- Clear buffer
------------------
local retval = reaper.GetMediaItemTake_Peaks(take, peakrate, starttime, n_chans, n_spls, want_extra_type, buf);
local spl_cnt = (retval & 0xfffff) -- sample_count
local ext_type = (retval & 0x1000000)>>24 -- extra_type was available
local out_mode = (retval & 0xf00000)>>20 -- output_mode
------------------
Peaks = {}
if spl_cnt > 0 and ext_type > 0 then
for i = 1, n_spls do
local p = #Peaks
Peaks[p+1] = buf[i] -- max peak
Peaks[p+2] = buf[i+2] -- min peak
Peaks[p+3] = buf[n_spls+i] -- max peak
Peaks[p+4] = buf[n_spls + i+2] -- min peak
end
end
------------------
return Peaks
end
---------------------------
function Project_IsChanged()
local cur_cnt = reaper.GetProjectStateChangeCount(0)
if cur_cnt ~= proj_change_cnt then proj_change_cnt = cur_cnt
return true
end
end
---------------------------
function main()
if Project_IsChanged() then
gfx.setimgdim(0, 0, 0) -- clear buf 0
gfx.setimgdim(0, gfx.w, gfx.h)
gfx.dest = 0; -- set dest buf = 0
local item = reaper.GetSelectedMediaItem(0, 0)
if item then
local Peaks = Item_GetPeaks(item)
if Peaks then Peaks_Draw(Peaks) end
end
end
-----------
local img_w, img_h = gfx.getimgdim(0)
if img_w > 0 and img_h > 0 then
gfx.a = 1; gfx.dest = -1; gfx.x, gfx.y = 0, 0
gfx.blit(image, 1, 0, 0, 0, img_w, img_h, 0, 0, gfx.w, gfx.h)
end
-----------
char = gfx.getchar()
if char == 32 then reaper.Main_OnCommand(40044, 0) end -- play
if char ~= -1 then reaper.defer(main) end -- defer
-----------
gfx.update()
-----------
end
Init()
main()
|
|
|
01-03-2019, 10:15 AM
|
#32
|
Human being with feelings
Join Date: Sep 2018
Location: China
Posts: 565
|
Quote:
Originally Posted by X-Raym
Anyone would know how to make eugen code display multichannel ?
I tried to mod it without success so far:
|
Hi, there is a little question here. Why I can't see anything after running neither your script or Eugen's ? Just an empty window.
|
|
|
01-03-2019, 02:30 PM
|
#33
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
@dsyrock
My code snippet isn't really a 'script' like the scripts I showcased, just some experimental code :P
So the concept with Eugen script and this code snippet
- Select an item
- Run the action to build Spectral peaks if the items doesn't have them build already
|
|
|
06-05-2019, 01:47 PM
|
#34
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
So I haven't worked on this for a while, they are not perfect, and still a bit CPU intensive if you have lots of long items, but as I often use them, I released them in pack so you can enjoy them as they are:
https://forum.cockos.com/showpost.ph...18&postcount=3
Enjoy !
|
|
|
06-05-2019, 11:09 PM
|
#35
|
Human being with feelings
Join Date: Feb 2017
Posts: 305
|
|
|
|
06-07-2019, 05:05 AM
|
#36
|
Human being with feelings
Join Date: Jun 2009
Location: South, UK
Posts: 14,214
|
Looks useful.
For looping.. Would it be possible to instead of showing the start/end of the item. Could it instead show the start/end of the cycle/loop region of the arrange page instead?
That would be super useful. So basically what you have in the overview script but divided to show the loop start/end instead.
__________________
subproject FRs click here
note: don't search for my pseudonym on the web. The "musicbynumbers" you find is not me or the name I use for my own music.
|
|
|
06-07-2019, 08:04 AM
|
#37
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
@musicbynumbers
Hi ! thx
Can you show me what you mean loop cycle ? To be sure I get it :P
|
|
|
06-08-2019, 03:58 AM
|
#38
|
Human being with feelings
Join Date: Jun 2009
Location: South, UK
Posts: 14,214
|
Sure. Not near reaper to take a screen capture yet but I'll try and be more detailed below
I mean reaper's loop region at the top of the arrange page that actually is using for looping/cycling whilst playing in the arrange area.
If you were able to show exactly what you've done for the end and start of an item but instead, show the end and start of the summed items on the selected tracks at the point at which the loop regions end and start that would be super useful.
That way, the user could adjust the loop region at top of arrange and in real-time be able to see (and more importantly "hear") whether the selected area is looping well.
then, you adjust the items start and end to match the loop area.
This is much more intuitive then trying to first do this soley on the item level as you then have to set loop region to the item to hear it.
Also, most of the time, when doing say ambience SFX loops (for games), you are often mixing multiple tracks at once to get the right feel so being able to see a sum of these at the top of the screen zoomed into the loop points is super useful.
If that isn't clear though, let me know and I'll do a diagram when I've got time and back in the studio.
__________________
subproject FRs click here
note: don't search for my pseudonym on the web. The "musicbynumbers" you find is not me or the name I use for my own music.
|
|
|
06-12-2019, 05:10 AM
|
#40
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
@musicbynumbers
Ok I understand both of your requests :P
For the using Loop section, that make sense (cause it helps audition the part), and it should be possible
For multiple source at the same time, well, non looped version of this is what it is designed for :P It only miss the loop feature somehow.
I'll keep that in mind but lets first see if the pack interest other users as it is.
Most important step for me is multichannel display at this point :P
|
|
|
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:52 AM.
|