Old 08-13-2018, 11:34 AM   #1
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default New Script: Cubase style multi-cut with mouse

EDIT - 2018-09-16 -- updated script to fix a bug if cursor was exactly at item start.

Hi guys,

I wrote a script for a feature I found missing in Reaper. Not sure if another script out there does the same, but I couldn't find it. This is especially useful when invoking the script by Arming an Icon by right-clicking it (as seen in the GIF).

Currently I called it: Cut item repeatedly based on initial cut length but I'm 100% open to a better name. I don't think calling it "Cubase Style Multi Cut" will help anyone who hasn't used Cubase.

Basically, when this script is on, wherever you click an item with the mouse, it will repeat the cut at equal intervals based on the size of your first cut. Snap can be ON to guide the cut or it can be wild. So if you cut 1 bar into the Item, then there will be subsequent 1 bar cuts to that item until the end of the initial item. It's easier to show on a GIF. In this example I had Snap set to bars:



Here is the code:

Code:
--[[
    Description: Cut item repeatedly based on initial cut length
    Version: 1.0.0
    Author: Thonex
]]--

function Cut_item_repeatedly_based_on_initial_cut_length ()
  reaper.PreventUIRefresh(1)
  reaper.Undo_BeginBlock()
  reaper.ClearConsole()


  -- Get initial len and starting item -- 
  Cur_Pos =  reaper.GetCursorPosition() -- to get length by subtracting item start
  Item_ID = reaper.GetSelectedMediaItem(0,0)
  
  if Item_ID == nil then -- exit function if nothing is selected
    return
  end
  
  Start = reaper.GetMediaItemInfo_Value( Item_ID, "D_POSITION")
  
  if Cur_Pos <= Start then -- exit if cursor pos = item start (causes crash)
    return
  end
  
  Item_Len = reaper.GetMediaItemInfo_Value( Item_ID, "D_LENGTH")
  Len = Cur_Pos-Start -- used to how long to make the cuts
  
  Num_Cuts = math.floor(Item_Len/Len)
  
  for i=0, Num_Cuts do -- Sart loop here to see if next item is contiguous
   
    reaper.Main_OnCommand(40012, 0 ) -- Item: Split items at edit or play cursor
    
    Item_ID = reaper.GetSelectedMediaItem(0,0)
    Start = reaper.GetMediaItemInfo_Value( Item_ID, "D_POSITION")
    Next_Len = reaper.GetMediaItemInfo_Value( Item_ID, "D_LENGTH")

    reaper.SetEditCurPos( Start+Len, 0, 0 )
   
  end
    reaper.SetEditCurPos( Cur_Pos, 0, 0 ) -- set back to inital location before script
    reaper.SelectAllMediaItems( 0, 0 )

  
  reaper.PreventUIRefresh(-1)
  reaper.UpdateArrange()
  reaper.Undo_EndBlock("Cuts based on Cursor",-1)
end


Cut_item_repeatedly_based_on_initial_cut_length ()
__________________
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.

Last edited by Thonex; 09-16-2018 at 11:00 AM.
Thonex is offline   Reply With Quote
Old 08-13-2018, 11:42 AM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,874
Default

Nice idea ! :P
X-Raym is offline   Reply With Quote
Old 08-13-2018, 11:45 AM   #3
vanhaze
Human being with feelings
 
vanhaze's Avatar
 
Join Date: Jul 2012
Location: Netherlands
Posts: 5,247
Default

This is incredibly useful !
Reminds of same kind of functionality in Logic Pro X, using it's Scissors Tool while CMD key.

Thank you !!
__________________
Macbook Pro INTEL | Reaper, always latest version | OSX Ventura | Presonus Studio 24c
My Reaper Tips&Tricks YouTube Channel: https://www.youtube.com/user/vanhaze2000/playlists
vanhaze is offline   Reply With Quote
Old 08-13-2018, 12:10 PM   #4
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

I seem to have made something similar: https://forum.cockos.com/showthread.php?t=150708

(not exactly the same as your script, though )
spk77 is offline   Reply With Quote
Old 08-13-2018, 12:20 PM   #5
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
Default

Awesome Andrew! I had this on my todo list
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 08-13-2018, 12:20 PM   #6
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,874
Default

@spk77
I knew I saw that before ! ^^
It isn't in reapack so I missed it :P



@Thonex
Even better:


https://github.com/ReaTeam/ReaScript...it%20items.lua
X-Raym is offline   Reply With Quote
Old 08-13-2018, 12:21 PM   #7
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Quote:
Originally Posted by spk77 View Post
I seem to have made something similar: https://forum.cockos.com/showthread.php?t=150708

(not exactly the same as your script, though )
@spk77

Nice one! Is that multi-selection friendly and Snap friendly? Is so, I think it is indeed the same... no?
__________________
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.

Last edited by Thonex; 08-13-2018 at 01:09 PM.
Thonex is offline   Reply With Quote
Old 08-13-2018, 12:23 PM   #8
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,874
Default

@Thonex
BWT, you definitly have to consider GitHub and Reapack now :P Escpeially if you have to update your scripts.
X-Raym is offline   Reply With Quote
Old 08-13-2018, 11:51 AM   #9
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Quote:
Originally Posted by X-Raym View Post
Nice idea ! :P
Thanks X-Raym,

I wish I could take credit for it... but Cubase cir. 1990 LOL
__________________
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.
Thonex is offline   Reply With Quote
Old 08-13-2018, 11:56 AM   #10
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Edited the code... removed an unnecessary line of code (Continue = 1). That was a vestige of a previous version.

All cleaned up now.
__________________
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.
Thonex is offline   Reply With Quote
Old 08-13-2018, 11:58 AM   #11
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Neat idea.

For future reference, we also have this in the API:

Quote:
MediaItem reaper.SplitMediaItem(MediaItem item, number position)

The original item becomes the left-hand split, the function returns the right-hand split (or NULL if the split failed)
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 08-13-2018, 12:07 PM   #12
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Quote:
Originally Posted by Lokasenna View Post
Neat idea.

For future reference, we also have this in the API:
Oooohhh.... thanks Loka!!

Will check it out. Maybe I can shave a bunch of code from my script.
__________________
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.
Thonex is offline   Reply With Quote
Old 08-13-2018, 12:18 PM   #13
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Quote:
Originally Posted by Lokasenna View Post
Neat idea.

For future reference, we also have this in the API:
Ok... on first blush, that function is not as multi-item friendly as splitting with reaper.Main_OnCommand(40012, 0 ) -- Item: Split items at edit or play cursor

I think i'd have to eventually do more item checks than the code I have now.

But very nice to know about that function now

Love Reaper... love the community! And thanks yet again for you help Loka!
__________________
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.
Thonex is offline   Reply With Quote
Old 08-13-2018, 12:03 PM   #14
vanhaze
Human being with feelings
 
vanhaze's Avatar
 
Join Date: Jul 2012
Location: Netherlands
Posts: 5,247
Default

Quote:
Originally Posted by Thonex View Post
Edited the code... removed an unnecessary line of code (Continue = 1). That was a vestige of a previous version.

All cleaned up now.
Thanks !!
__________________
Macbook Pro INTEL | Reaper, always latest version | OSX Ventura | Presonus Studio 24c
My Reaper Tips&Tricks YouTube Channel: https://www.youtube.com/user/vanhaze2000/playlists
vanhaze is offline   Reply With Quote
Old 08-16-2018, 01:28 PM   #15
Vagelis
Human being with feelings
 
Vagelis's Avatar
 
Join Date: Oct 2017
Location: Larisa, Greece
Posts: 3,795
Default

Very useful script,thanks!
Vagelis is offline   Reply With Quote
Old 09-16-2018, 11:02 AM   #16
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Updated the OP with a new version of the script that fixed crash when trying to cut an item at exactly it's start (divide by zero crash I suspect.... )

Cheers!
__________________
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.
Thonex is offline   Reply With Quote
Old 02-22-2019, 04:51 AM   #17
Vagelis
Human being with feelings
 
Vagelis's Avatar
 
Join Date: Oct 2017
Location: Larisa, Greece
Posts: 3,795
Default

Hi Thonex, as a previous Cubase user, i use a lot this script for editing.
I came back to ask if it's possible to update it so it could split the same way Automations Items.That would be really great.
Thanks in advance

Last edited by Vagelis; 02-22-2019 at 08:16 AM.
Vagelis is offline   Reply With Quote
Old 02-27-2019, 07:56 AM   #18
beingmf
Human being with feelings
 
beingmf's Avatar
 
Join Date: Jul 2007
Location: Jazz City
Posts: 5,065
Default

Very cool! Thanks a lot - I also remember using this quite a lot during my Logic days.
__________________
Windows 10x64 | AMD Ryzen 3700X | ATI FirePro 2100 | Marian Seraph AD2, 4.3.8 | Yamaha Steinberg MR816x
"If I can hear well, then everything I do is right" (Allen Sides)
beingmf is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:40 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.