Old 08-28-2015, 06:17 PM   #1
swiiscompos
Human being with feelings
 
swiiscompos's Avatar
 
Join Date: Mar 2011
Location: London
Posts: 1,211
Default Lua: Smart Layout Changer

Hi folks,

Here is my first LUA script created with the huge help of Sexan and Jeffos. It changes the track layout depending on the track content (audio, MIDI or video) or on the track state/function (folder, aux, separator). The script requires Reaper V5.02+ and the SWS extensions. To make it work you will also need to set up the layout actions in the Screensets/Layouts window like this:

RecArmLayTCP --ACTION 1
FolderLayTCP --ACTION 2
SeparatorLayTCP--ACTION 3
AuxLayTCP --ACTION 4
MidiLayTCP --ACTION 5
VideoLayTCP --ACTION 6
MixedLayTCP --ACTION 7

Same order for MCP but from 8-14



Here is the link for the Windows version:
https://stash.reaper.fm/25048/SmartLayoutOptimized.lua

And here is the link for the Mac version:
https://stash.reaper.fm/25210/SmartLa...timizedOSX.lua

Last edited by swiiscompos; 09-25-2015 at 09:09 AM.
swiiscompos is offline   Reply With Quote
Old 08-29-2015, 01:53 AM   #2
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

for running in background is easy,all you need to add :
"reaper.defer(Main)" before last end
Sexan is offline   Reply With Quote
Old 08-29-2015, 04:04 AM   #3
beingmf
Human being with feelings
 
beingmf's Avatar
 
Join Date: Jul 2007
Location: Jazz City
Posts: 5,065
Default

GREAT IDEA (especially with the "run in background" command)!

I think it will be extremely useful for
- Midi
- Audio
- Video
- Recording (rec button armed)
__________________
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
Old 08-29-2015, 04:04 AM   #4
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

Here is defered script with Folder state layout change:
Code:
function Main()

-- COUNT TRACKS
  count_tracks = reaper.CountTracks(0)
  
  -- LOOP FOR EVERY TRACK
  for i = 0, count_tracks -1 do
      track = reaper.GetTrack(0, i)
      retval, TrackState = reaper.GetTrackState(track)     --------ADDED----------------- CHECK TRACK STATE 
      count_items_track = reaper.CountTrackMediaItems(track)           
    
    -- LOOP FOR EVERY ITEM
  for j = 0, count_items_track -1 do
    item = reaper.GetTrackMediaItem(track, j)

  -- CHECK THE FIRST TAKE OF ITEM TO DETERMINE SOURCE TYPE 
    take = reaper.GetMediaItemTake(item, 0)
        source = reaper.GetMediaItemTake_Source(take)
         take_type = reaper.GetMediaSourceType(source, "test")
         _G["take_type"..j] = take_type
    end 
      
  item_check = 1 --ITEMS IN TRACK ARE CONSIDERED TO BE ALL SIMILAR
  if count_items_track >= 2  then 
    
  --CHECK IF SOME ITEMS IN TRACK DON'T MATCH
  for l = 0, count_items_track -2 do
    m = (l + 1)
    if take_type0 ~= _G["take_type"..m] then
      reaper.BR_SetMediaTrackLayouts(track, "aa - Standard", "aa - Standard")
      item_check = 0
      break
    end
  end
  end      
      
      --IF ALL THE ITEMS MATCH CHECK THE SOURCE TYPE AND CHANGE TRACK LAYOUT
      if item_check == 1 and count_items_track > 0 then
      
      if take_type0 == "MIDI" then
        reaper.BR_SetMediaTrackLayouts(track, "", "aa - Standard - Untinted")
        
      elseif take_type0 == "VIDEO" then
        reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")
      
      else
        reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")            
      end
      end
      
      ----IF TRACK IS FOLDER WITH NO ITEMS (ANY STATE WITH 1 -----------------------ADDED
      if (TrackState &1) == 1 and count_items_track == 0 then
          reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")
          
      ----INITIAL LAYOUT STATE
      elseif count_items_track == 0 then
          reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
      end
      ------------------------------------------------------------------------------------------ADDED
  end
  
reaper.defer(Main)    
end

Main()
But there are some graphical glitches when layout changes (don't know why)

I've already added code for that , now you just have to check states (I checked for Folder state):

Lua: string retval, number flagsOut reaper.GetTrackState(MediaTrack track)

&1=folder
&2=selected
&4=has fx enabled
&8=muted
&16=soloed
&32=SIP'd (with &16)
&64=rec armed

BTW thank you for this script!

Last edited by Sexan; 09-04-2015 at 02:34 AM.
Sexan is offline   Reply With Quote
Old 08-29-2015, 04:35 AM   #5
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

If anyone could please explain how to use flags I would appreciate it

Edit : NEVERMIND
Code:
retval, TrackState  = reaper.GetTrackState(track)
if (TrackState &1) == 1 then
(TrackState &2) == 2
(TrackState &8) == 8
Done!
Code:
function Main()

-- COUNT TRACKS
  count_tracks = reaper.CountTracks(0)
  
 -- LOOP FOR EVERY TRACK
  for i = 0, count_tracks -1 do
      track = reaper.GetTrack(0, i)
      retval, TrackState = reaper.GetTrackState(track)     --------ADDED----------------- CHECK TRACK STATE 
      count_items_track = reaper.CountTrackMediaItems(track)           
    
    -- LOOP FOR EVERY ITEM
  for j = 0, count_items_track -1 do
    item = reaper.GetTrackMediaItem(track, j)       
      
  -- CHECK THE FIRST TAKE OF ITEM TO DETERMINE SOURCE TYPE 
    
    take = reaper.GetMediaItemTake(item, 0)    
        source = reaper.GetMediaItemTake_Source(take)       
         take_type = reaper.GetMediaSourceType(source, "test")         
         _G["take_type"..j] = take_type
         
    end
         
  item_check = 1 --ITEMS IN TRACK ARE CONSIDERED TO BE ALL SIMILAR
  if count_items_track >= 2  then 
    
  --CHECK IF SOME ITEMS IN TRACK DON'T MATCH
  for l = 0, count_items_track -2 do
    m = (l + 1)
    if take_type0 ~= _G["take_type"..m] then
      reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
      item_check = 0
      break
    end
  end
  end
        
      --IF ALL THE ITEMS MATCH CHECK THE SOURCE TYPE AND CHANGE TRACK LAYOUT
      if item_check == 1 and count_items_track > 0 then
      
      if take_type0 == "MIDI" and TrackState < 64 then
        reaper.BR_SetMediaTrackLayouts(track, "", "aa - Standard")   
      
      elseif take_type0 == "MIDI" and TrackState >= 64 then    ----------------rec arm enabled
        reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")              
      
      elseif take_type0 == "VIDEO" then
        reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")     
      
      elseif take_type0 == "WAVE" and TrackState < 64 then    
        reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
      
      elseif take_type0 == "WAVE" and TrackState >= 64 then    ----------------rec arm enabled
        reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")     
      
      end
      end
     
      ----IF TRACK IS FOLDER WITH NO ITEMS -----------------------ADDED
      if count_items_track == 0 then
        if (TrackState &1) == 1 then
            reaper.BR_SetMediaTrackLayouts(track, "", "ai --- Standard Live Recording")      
          
      ----INITIAL LAYOUT STATE
        elseif TrackState < 64 then                           --------------------Default Layout
            reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
          
        elseif TrackState >= 64 then                           ----------------rec arm enabled
          reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")       
     
        
      end
      end
      ------------------------------------------------------------------------------------------ADDED
  end
  
reaper.defer(Main)    
end

Main()
I've commented what I added



Changes layout on:
Rec-arm state and Folder State

Need to fix this corrupted graphics.... don't know why it happens

Last edited by Sexan; 08-29-2015 at 10:11 AM.
Sexan is offline   Reply With Quote
Old 08-29-2015, 12:02 PM   #6
swiiscompos
Human being with feelings
 
swiiscompos's Avatar
 
Join Date: Mar 2011
Location: London
Posts: 1,211
Default

Thanks a lot Sexan! Looks like my small project is actually becoming usable! It works perfectly... except I get the same graphical bugs. Hopefully it's not a bug with the reaper.BR_SetMediaTrackLayouts() itself. I will do some testing.
swiiscompos is offline   Reply With Quote
Old 08-29-2015, 12:05 PM   #7
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

I think the next step is to define layouts some how so users don't have to write them themselves,But this is one of scripts I wanted for a long time,so thank you!
I thought it would be cool to add track icons the same way but there is no api for that

Maybe you should rename the thread name to something like "Smart Layout Changer"

More Ideas :
If folder has only midi items change layout of folder,the same for video and wave

Last edited by Sexan; 08-29-2015 at 12:24 PM.
Sexan is offline   Reply With Quote
Old 08-29-2015, 12:37 PM   #8
swiiscompos
Human being with feelings
 
swiiscompos's Avatar
 
Join Date: Mar 2011
Location: London
Posts: 1,211
Default

I did some test and it looks like the graphic problems comes from the SetMediaTrackLayouts. I will forward that to the SWS coders.
swiiscompos is offline   Reply With Quote
Old 08-29-2015, 12:50 PM   #9
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

There is one more problem.everything works fine until you import track,then rec enable layout won't work.

Edit:Oh my fast fingers,,,,we need to add MP3 type
Sexan is offline   Reply With Quote
Old 08-29-2015, 01:06 PM   #10
swiiscompos
Human being with feelings
 
swiiscompos's Avatar
 
Join Date: Mar 2011
Location: London
Posts: 1,211
Default

Quote:
Originally Posted by Sexan View Post
Edit:Oh my fast fingers,,,,we need to add MP3 type
That's why I didn't check for the audio type in my script but used "else" instead, so that all audio formats would be taken into account.
swiiscompos is offline   Reply With Quote
Old 08-29-2015, 01:21 PM   #11
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

Quote:
Originally Posted by swiiscompos View Post
That's why I didn't check for the audio type in my script but used "else" instead, so that all audio formats would be taken into account.
Oh.I've modified that because of state condition (can we put that in else?)
Sexan is offline   Reply With Quote
Old 08-29-2015, 01:25 PM   #12
beingmf
Human being with feelings
 
beingmf's Avatar
 
Join Date: Jul 2007
Location: Jazz City
Posts: 5,065
Default

Quote:
Originally Posted by Sexan View Post
Marvellous! Once working without glitches, this track behaviour should be part of the original installer!
__________________
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
Old 08-29-2015, 01:42 PM   #13
swiiscompos
Human being with feelings
 
swiiscompos's Avatar
 
Join Date: Mar 2011
Location: London
Posts: 1,211
Default

With the help of Breeder I found a way to avoid the glitches. I will change the code for the moment but the function should be updated in the next SWS release.
swiiscompos is offline   Reply With Quote
Old 08-29-2015, 01:44 PM   #14
swiiscompos
Human being with feelings
 
swiiscompos's Avatar
 
Join Date: Mar 2011
Location: London
Posts: 1,211
Default

Quote:
Originally Posted by Sexan View Post
Oh.I've modified that because of state condition (can we put that in else?)
No idea, it's only my second day scripting. But maybe there is a clean way to check for all the audio types...
swiiscompos is offline   Reply With Quote
Old 08-29-2015, 02:16 PM   #15
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

It will need to defined in take section with if loop: if taketype = midi then type = m ....for video = v ,if item count = 0 type = non and for else = a ....then use that for checking instead if type "midi" ...

Last edited by Sexan; 08-29-2015 at 02:23 PM.
Sexan is offline   Reply With Quote
Old 08-29-2015, 02:24 PM   #16
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@swiiscompos
Wow, you did all that just after watching ONE of my video ? Thus is so cool, I'l glad you liked it !
Good luck with your scriot, you are in good hands :P
X-Raym is offline   Reply With Quote
Old 08-29-2015, 02:30 PM   #17
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

I will update the code with new types soon
Sexan is offline   Reply With Quote
Old 08-29-2015, 02:48 PM   #18
swiiscompos
Human being with feelings
 
swiiscompos's Avatar
 
Join Date: Mar 2011
Location: London
Posts: 1,211
Default

Quote:
Originally Posted by X-Raym View Post
@swiiscompos
Wow, you did all that just after watching ONE of my video ? Thus is so cool, I'l glad you liked it !
Good luck with your scriot, you are in good hands :P
No, 6 videos. Mais merci, elles étaient très utiles!
swiiscompos is offline   Reply With Quote
Old 08-29-2015, 02:52 PM   #19
swiiscompos
Human being with feelings
 
swiiscompos's Avatar
 
Join Date: Mar 2011
Location: London
Posts: 1,211
Default

Actually it's more complicated than I thought to fix the glitches because the workaround is to hide/unhide the mcp master and hide/unhide the tracks. But because it's a defer() code these actions keep being called making the tcp and the mixer unusable. Does anyone know how to fix that?
swiiscompos is offline   Reply With Quote
Old 08-29-2015, 02:55 PM   #20
Reno.thestraws
Human being with feelings
 
Reno.thestraws's Avatar
 
Join Date: Nov 2009
Location: Belgium
Posts: 10,474
Default

Try

reaper.TrackList_AdjustWindows(boolean isMinor)

For graphitât bugs
__________________
http://www.residenceemilia.com
Reno.thestraws is offline   Reply With Quote
Old 08-29-2015, 03:04 PM   #21
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

Reno, does it matter if that command is at beginning or at end? Btw I've tried it few hours ago and didn't make any difference ? Maybe I'm using it wrong?

Anyway new code with proper flags and item types:

Code:
function Main()

Folder = 1
Selected = 2
FX = 4
Mute = 8
Solo = 16
SIP = 32
RecArm = 64


-- COUNT TRACKS
  count_tracks = reaper.CountTracks(0)
  
 -- LOOP FOR EVERY TRACK
  for i = 0, count_tracks -1 do
      track = reaper.GetTrack(0, i)
      retval, TrackState = reaper.GetTrackState(track)      
      count_items_track = reaper.CountTrackMediaItems(track)           
    
    -- LOOP FOR EVERY ITEM
    for j = 0, count_items_track -1 do
        item = reaper.GetTrackMediaItem(track, j)       
      
  -- CHECK THE FIRST TAKE OF ITEM TO DETERMINE SOURCE TYPE 
    
        take = reaper.GetMediaItemTake(item, 0)    
        source = reaper.GetMediaItemTake_Source(take)       
        take_type = reaper.GetMediaSourceType(source, "test")                 
        _G["take_type"..j] = take_type
     
   ---- TAKE TYPES -----------------------------------------       
          if take_type == "MIDI" then
             RTakeType = "M"
          elseif take_type == "VIDEO" then
             RTakeType = "V"
          else
             RTakeType = "A"
          end
          
         
    end
         
        item_check = 1 --ITEMS IN TRACK ARE CONSIDERED TO BE ALL SIMILAR
     if count_items_track >= 2  then 
    
  --CHECK IF SOME ITEMS IN TRACK DON'T MATCH
        for l = 0, count_items_track -2 do
            m = (l + 1)
          if take_type0 ~= _G["take_type"..m] then
            reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
            item_check = 0
          break
        end
     end
  end
        
      --IF ALL THE ITEMS MATCH CHECK THE SOURCE TYPE AND CHANGE TRACK LAYOUT
  if item_check == 1 and count_items_track > 0 then
      
      -----------------------------------------------------------MIDI-------------------
     if RTakeType == "M" and (TrackState &64) ~= RecArm then
        reaper.BR_SetMediaTrackLayouts(track, "", "aa - Standard")   
      
        elseif RTakeType == "M" and (TrackState &64) == RecArm then    ----------------REC-ARM
               reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")              
     
      -----------------------------------------------------------VIDEO------------------
      
        elseif RTakeType == "V"  and (TrackState &64) ~= RecArm then
               reaper.BR_SetMediaTrackLayouts(track, "", "ba - Small")
        
        elseif RTakeType == "V" and (TrackState &64) == RecArm then   ----------------REC-ARM
               reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")       
      -----------------------------------------------------------WAVE-------------------
    
        elseif RTakeType == "A" and (TrackState &64) ~= RecArm then    
               reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
      
        elseif RTakeType == "A" and (TrackState &64) == RecArm then    ----------------REC-ARM
               reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")
      
     end
  end
     
      ------------------------NO ITEMS -------------------------------------------------
      ----IF TRACK IS FOLDER------------------------------------------------------------
      if count_items_track == 0 then
          if (TrackState &1) == Folder then
              reaper.BR_SetMediaTrackLayouts(track, "", "ai --- Standard Live Recording")      
          
      --------------------------------DEFAULT LAYOUT------------------------------------
          elseif (TrackState &64) ~= RecArm then                           
                 reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
          
          elseif (TrackState &64) == RecArm then                 ----------------REC-ARM
                 reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")       
     
        
          end
      end
      
  end

reaper.defer(Main)    
end

Main()

Last edited by Sexan; 08-29-2015 at 03:28 PM.
Sexan is offline   Reply With Quote
Old 08-29-2015, 03:17 PM   #22
swiiscompos
Human being with feelings
 
swiiscompos's Avatar
 
Join Date: Mar 2011
Location: London
Posts: 1,211
Default

Found how to fix the glitch. New code coming soon! By the way Sexan, how many spaces for a tab do you use?
swiiscompos is offline   Reply With Quote
Old 08-29-2015, 03:21 PM   #23
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

Quote:
Originally Posted by swiiscompos View Post
Found how to fix the glitch. New code coming soon! By the way Sexan, how many spaces for a tab do you use?
Don't know I tab them till they look good doesn't matter.I try to get IF and its END together in the same "line",for all loops
Sexan is offline   Reply With Quote
Old 08-29-2015, 03:34 PM   #24
Reno.thestraws
Human being with feelings
 
Reno.thestraws's Avatar
 
Join Date: Nov 2009
Location: Belgium
Posts: 10,474
Default

here's is it

no graphical glitch

Code:
function Main()

Folder = 1
Selected = 2
FX = 4
Mute = 8
Solo = 16
SIP = 32
RecArm = 64


-- COUNT TRACKS
  count_tracks = reaper.CountTracks(0)
  
 -- LOOP FOR EVERY TRACK
  for i = 0, count_tracks -1 do
      track = reaper.GetTrack(0, i)
      retval, TrackState = reaper.GetTrackState(track)      
      count_items_track = reaper.CountTrackMediaItems(track)           
    
    -- LOOP FOR EVERY ITEM
    for j = 0, count_items_track -1 do
        item = reaper.GetTrackMediaItem(track, j)       
      
  -- CHECK THE FIRST TAKE OF ITEM TO DETERMINE SOURCE TYPE 
    
        take = reaper.GetMediaItemTake(item, 0)    
        source = reaper.GetMediaItemTake_Source(take)       
        take_type = reaper.GetMediaSourceType(source, "test")                 
        _G["take_type"..j] = take_type
     
   ---- TAKE TYPES -----------------------------------------       
          if take_type == "MIDI" then
             RTakeType = "M"
          elseif take_type == "VIDEO" then
             RTakeType = "V"
          else
             RTakeType = "A"
          end
          
         
    end
         
        item_check = 1 --ITEMS IN TRACK ARE CONSIDERED TO BE ALL SIMILAR
     if count_items_track >= 2  then 
    
  --CHECK IF SOME ITEMS IN TRACK DON'T MATCH
        for l = 0, count_items_track -2 do
            m = (l + 1)
          if take_type0 ~= _G["take_type"..m] then
            reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
            item_check = 0
          break
        end
     end
  end
        
      --IF ALL THE ITEMS MATCH CHECK THE SOURCE TYPE AND CHANGE TRACK LAYOUT
  if item_check == 1 and count_items_track > 0 then
      
      -----------------------------------------------------------MIDI-------------------
     if RTakeType == "M" and (TrackState &64) ~= RecArm then
        reaper.BR_SetMediaTrackLayouts(track, "", "aa - Standard")   
      
        elseif RTakeType == "M" and (TrackState &64) == RecArm then    ----------------REC-ARM
               reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")              
     
      -----------------------------------------------------------VIDEO------------------
      
        elseif RTakeType == "V"  and (TrackState &64) ~= RecArm then
               reaper.BR_SetMediaTrackLayouts(track, "", "ba - Small")
        
        elseif RTakeType == "V" and (TrackState &64) == RecArm then   ----------------REC-ARM
               reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")       
      -----------------------------------------------------------WAVE-------------------
    
        elseif RTakeType == "A" and (TrackState &64) ~= RecArm then    
               reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
      
        elseif RTakeType == "A" and (TrackState &64) == RecArm then    ----------------REC-ARM
               reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")
      
     end
  end
     
      ------------------------NO ITEMS -------------------------------------------------
      ----IF TRACK IS FOLDER------------------------------------------------------------
      if count_items_track == 0 then
          if (TrackState &1) == Folder then
              reaper.BR_SetMediaTrackLayouts(track, "", "ai --- Standard Live Recording")      
          
      --------------------------------DEFAULT LAYOUT------------------------------------
          elseif (TrackState &64) ~= RecArm then                           
                 reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
          
          elseif (TrackState &64) == RecArm then                 ----------------REC-ARM
                 reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")       
     
        
          end
      end
      
  end
reaper.TrackList_AdjustWindows(1)
reaper.UpdateArrange()
reaper.defer(Main)    
end

Main()
__________________
http://www.residenceemilia.com
Reno.thestraws is offline   Reply With Quote
Old 08-29-2015, 03:40 PM   #25
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

Quote:
Originally Posted by Reno.thestraws View Post
here's is it

no graphical glitch
hm..still getting glitch when rec arm and unarm tracks
Sexan is offline   Reply With Quote
Old 08-29-2015, 03:52 PM   #26
swiiscompos
Human being with feelings
 
swiiscompos's Avatar
 
Join Date: Mar 2011
Location: London
Posts: 1,211
Default

Quote:
Originally Posted by Sexan View Post
hm..still getting glitch when rec arm and unarm tracks
Yes, because it's the problematic layout and UpdateArrange doesn't work.

Here is my fix. It works but it makes the script a little bit "blinky" when the tracks are updated. I will see if I can find a better solution but I will be very busy in the next few days.

EDIT: New code, fixed two small mistakes.

Code:
function Main()

Folder = 1
FX = 4
Mute = 8
Solo = 16
SIP = 32
RecArm = 64

	----SAVE TRACK SELECTION
	save_track_sel = reaper.NamedCommandLookup("_SWS_SAVESEL")
	reaper.Main_OnCommand(save_track_sel, 0)

	----COUNT TRACKS
  	count_tracks = reaper.CountTracks(0)
  
	----LOOP FOR EVERY TRACK
	for i = 0, count_tracks -1 do
      track = reaper.GetTrack(0, i)
      retval, TrackState = reaper.GetTrackState(track)      
      count_items_track = reaper.CountTrackMediaItems(track)           
    
	----LOOP FOR EVERY ITEM
    for j = 0, count_items_track -1 do
        item = reaper.GetTrackMediaItem(track, j)       
      
		----CHECK THE FIRST TAKE OF ITEM TO DETERMINE SOURCE TYPE 
    
        take = reaper.GetMediaItemTake(item, 0)    
        source = reaper.GetMediaItemTake_Source(take)       
        take_type = reaper.GetMediaSourceType(source, "test")         
        _G["take_type"..j] = take_type
          
          if take_type == "MIDI" then
             RTakeType = "M"
          elseif take_type == "VIDEO" then
             RTakeType = "V"
          else
             RTakeType = "A"
          end
          
         
		end
         
        item_check = 1 --ITEMS IN TRACK ARE CONSIDERED TO BE ALL SIMILAR
     if count_items_track >= 2  then 
    
		----CHECK IF SOME ITEMS IN TRACK DON'T MATCH
        for l = 0, count_items_track -2 do
            m = (l + 1)
          if take_type0 ~= _G["take_type"..m] then
            lay_change = reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
            item_check = 0
          break
        end
     end
  end
        
      ----IF ALL THE ITEMS MATCH CHECK THE SOURCE TYPE AND CHANGE TRACK LAYOUT
  if item_check == 1 and count_items_track > 0 then
      
      -----------------------------------------------------------MIDI-------------------
     if RTakeType == "M" and (TrackState &64) ~= RecArm then
        lay_change = reaper.BR_SetMediaTrackLayouts(track, "", "aa - Standard")   
      
        elseif RTakeType == "M" and (TrackState &64) == RecArm then    ----------------REC-ARM
               lay_change = reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")              
     
      -----------------------------------------------------------VIDEO------------------
      
        elseif RTakeType == "V"  and (TrackState &64) ~= RecArm then
               lay_change = reaper.BR_SetMediaTrackLayouts(track, "", "ba - Small")
        
        elseif RTakeType == "V" and (TrackState &64) == RecArm then   ----------------REC-ARM
               lay_change = reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")       
      -----------------------------------------------------------WAVE-------------------
    
        elseif RTakeType == "A" and (TrackState &64) ~= RecArm then    
               lay_change = reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
      
        elseif RTakeType == "A" and (TrackState &64) == RecArm then    ----------------REC-ARM
               lay_change = reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")
      
     end
  end
     
      ------------------------NO ITEMS -------------------------------------------------
      ----IF TRACK IS FOLDER------------------------------------------------------------
      if count_items_track == 0 then
          if (TrackState &1) == Folder then
              lay_change = reaper.BR_SetMediaTrackLayouts(track, "", "ai --- Standard Live Recording")      
          
      --------------------------------DEFAULT LAYOUT------------------------------------
          elseif (TrackState &64) ~= RecArm then                           
                 lay_change = reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
          
          elseif (TrackState &64) == RecArm then                 ----------------REC-ARM
                 lay_change = reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")       
     
        
          end
      end
      
	----WORKAROUND FOR GRAPHICAL GLITCHES ----------------------------------------
	is_track_visible = reaper.IsTrackVisible(track, false)
      
		if lay_change == true then
			if is_track_visible == true then
				reaper.SetOnlyTrackSelected(track)
				hide_sel_track = reaper.NamedCommandLookup("_SWSTL_HIDETCP")
				reaper.Main_OnCommand(hide_sel_track, 0)
			
				show_sel_track = reaper.NamedCommandLookup("_SWSTL_SHOWTCP")
				reaper.Main_OnCommand(show_sel_track, 0)
			end
			
			reaper.Main_OnCommand(41209, 0)
			reaper.Main_OnCommand(41209, 0)
		end
	end

	----RESTORE TRACK SELECTION-------------------------------------------------------------
	restore_track_sel = reaper.NamedCommandLookup("_SWS_RESTORESEL")
	reaper.Main_OnCommand(restore_track_sel, 0)
	----------------------------------------------------------------------------------------

	reaper.defer(Main)    
end

Main()

Last edited by swiiscompos; 08-29-2015 at 05:12 PM.
swiiscompos is offline   Reply With Quote
Old 08-29-2015, 04:09 PM   #27
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

Question for Script gurus :
1. How can I count number of tracks in folder?
2. How can I affect all children tracks? (If I rec-arm folder,to rec arm all children ?

So the question in global is how can I manipulate with folder tracks,Parent - Child and Child - parent?
Sexan is offline   Reply With Quote
Old 08-29-2015, 05:05 PM   #28
swiiscompos
Human being with feelings
 
swiiscompos's Avatar
 
Join Date: Mar 2011
Location: London
Posts: 1,211
Default

I found a way to avoid the graphical glitches without having the "blinky" effect but it's a workaroundish workaround (using the layouts) so I won't even share it. But I'm still searching a better solution, any help is welcome. (Problem is only with the TCP, no the MCP).
swiiscompos is offline   Reply With Quote
Old 08-30-2015, 09:22 AM   #29
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

Much simpler code (removed redundant code) and added AUX track layout change (if track has only receives and no items).

The Rec-Arm layout change is disabled for Folder and Aux (I think nobody ever records anything in that tracks)

Code:
-------TRACKS STATE FLAGS------------
--Folder = 1
--Selected = 2
--FX = 4
--Mute = 8
--Solo = 16
--SIP = 32
--RecArm = 64
function Main()

  -- COUNT TRACKS
  count_tracks = reaper.CountTracks(0)
 
  -- LOOP FOR EVERY TRACK
  for i = 0, count_tracks -1 do
      track = reaper.GetTrack(0, i)
      retval, TrackState = reaper.GetTrackState(track)
      count_items_track = reaper.CountTrackMediaItems(track)
      Receive = reaper.GetTrackNumSends(track, -1)     
      
      ----------------TRACK HAS RECEIVES ? ----------------------------       
        if Receive > 0 then
           HasReceive = 1
        else
           HasReceive = 0
        end
      -------------------TRACK STATES---------------------------------
      -------------------AUX TRACK-----------------------------------  
        if HasReceive == 1 and (TrackState &4) == 4 then
           Aux = 1
        else
           Aux = 0
        end
       --------------------------------------------------------------- 
       -------------------FOLDER TRACK--------------------------------  
       if (TrackState &1) == 1 then
           Folder = 1
       else
           Folder = 0
       end
       --------------------------------------------------------------- 
       -------------------REC-ARM TRACK-------------------------------  
       if (TrackState &64) == 64 then
           RecArm = 1
       else
           RecArm = 0
       end
       --------------------------------------------------------------- 
             
  -- LOOP FOR EVERY ITEM
    for j = 0, count_items_track -1 do
        item = reaper.GetTrackMediaItem(track, j)       
      
  -- CHECK THE FIRST TAKE OF ITEM TO DETERMINE SOURCE TYPE         
        take = reaper.GetMediaItemTake(item, 0)    
        source = reaper.GetMediaItemTake_Source(take)       
        take_type = reaper.GetMediaSourceType(source, "test")                 
        _G["take_type"..j] = take_type       
     
  ---- TAKE TYPES -----------------------------------------       
          if take_type == "MIDI" then
             RTakeType = "M"
          elseif take_type == "VIDEO" then
             RTakeType = "V"         
          else
             RTakeType = "A"
          end
  ---- TRACK TYPES ----------------------------------------        
          
    end
    
        item_check = 1 --ITEMS IN TRACK ARE CONSIDERED TO BE ALL SIMILAR
     if count_items_track >= 2  then 
    
  --CHECK IF SOME ITEMS IN TRACK DON'T MATCH
        for l = 0, count_items_track -2 do
            m = (l + 1)
          if take_type0 ~= _G["take_type"..m] then
            reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
            item_check = 0
          break
        end
     end
  end

      --IF ALL THE ITEMS MATCH CHECK THE SOURCE TYPE AND CHANGE TRACK LAYOUT
  ----------------------------TRACK HAS ITEMS ------------------------------------------
  if item_check == 1 and count_items_track > 0 and RecArm == 0 then
      ---------MIDI---------------------------------------------------------------------
     if RTakeType == "M" then
        reaper.BR_SetMediaTrackLayouts(track, "", "aa - Standard")
      ---------VIDEO--------------------------------------------------------------------
     elseif RTakeType == "V" then
            reaper.BR_SetMediaTrackLayouts(track, "", "ba - Small")     
      ---------AUDIO--------------------------------------------------------------------
     elseif RTakeType == "A" then    
            reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")     
     end
  end
  ----------------------------TRACK HAS ITEMS ------------------------------------------
        
      ------------------------NO ITEMS -------------------------------------------------
      --------FOLDER--------------------------------------------------------------------
      if count_items_track == 0 then
          if Folder == 1 then
              reaper.BR_SetMediaTrackLayouts(track, "", "ai --- Standard Live Recording") 
              
      --------AUX - HAS RECEIVES AND FX-------------------------------------------------
          elseif Aux == 1 then
              reaper.BR_SetMediaTrackLayouts(track, "", "ag --- Standard Compact")
      
      --------DEFAULT LAYOUT-------------------------------------------------------------
          elseif RecArm == 0 then                           
                 reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
          end
      end     
      -------------------------------**-------------------------------------------------
     
      ---------REC ARM LAYOUT------------------------------------------------------------  
      if count_items_track >= 0 and RecArm == 1 and Folder ~= 1 and Aux ~= 1 then
         reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")     
      end    
      ---------REC ARM LAYOUT------------------------------------------------------------  
  end
  

reaper.defer(Main)    
end

Main()
Folders and Aux don't change layout on Rec-Arm,so you know what type of track it is

Last edited by Sexan; 09-04-2015 at 02:35 AM.
Sexan is offline   Reply With Quote
Old 08-31-2015, 02:02 PM   #30
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

For some reason when track has FX (but you have more of them) it starts to lag heavily,not related to last script (I added FX checking),but any of them ??
Even if I remove all layout changing it lags heavily

Last edited by Sexan; 08-31-2015 at 02:12 PM.
Sexan is offline   Reply With Quote
Old 09-01-2015, 05:55 AM   #31
swiiscompos
Human being with feelings
 
swiiscompos's Avatar
 
Join Date: Mar 2011
Location: London
Posts: 1,211
Default

Sexan, did you see the last Reaper beta? Good news for us!
swiiscompos is offline   Reply With Quote
Old 09-01-2015, 05:59 AM   #32
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

Yeah , but still trying to figure out why tracks with FX cause big lags with script,I've tested with 100 tracks ,40 items per track etc. and it doesn't lag even remotely close as having 10 tracks with FX.

BTW line :

Code:
if take_type0 ~= _G["take_type"..m] then
            reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
            item_check = 0
Second line causes some trouble if there are few items on track
Sexan is offline   Reply With Quote
Old 09-01-2015, 06:09 AM   #33
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

Tested again with many MANY tracks with FX,and the problem starts when x86 plugins are on track
Sexan is offline   Reply With Quote
Old 09-01-2015, 06:16 AM   #34
swiiscompos
Human being with feelings
 
swiiscompos's Avatar
 
Join Date: Mar 2011
Location: London
Posts: 1,211
Default

I'm currently moving so today I won't have much time to test. Did you try the new native function to set the layout?
swiiscompos is offline   Reply With Quote
Old 09-02-2015, 01:04 PM   #35
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

Yeah I've tried,its glitch free but it seems to be more CPU hungry than sws version .IDE starts to lag soon as I run the script,which doesn't happen with old version.Maybe I'm using it wrong (which is more likely)?

Code:
function Main()
  -- COUNT TRACKS
  count_tracks = reaper.CountTracks(0)
 
  -- LOOP FOR EVERY TRACK
  for i = 0, count_tracks -1 do
      track = reaper.GetTrack(0, i)
      retval, TrackState = reaper.GetTrackState(track)
      count_items_track = reaper.CountTrackMediaItems(track)      
      receive = reaper.GetTrackNumSends(track, -1)     
      
      ----------------TRACK HAS RECEIVES ? ----------------------------      
        if receive > 0 then
           HasReceive = 1
        else
           HasReceive = 0
        end
      -------------------TRACK STATES---------------------------------
      -------------------AUX TRACK-----------------------------------  
       -- if HasReceive == 1 and (TrackState &4) == 4 then
       --    Aux = 1
      --  else
      --     Aux = 0
      --  end
       --------------------------------------------------------------- 
       -------------------FOLDER TRACK--------------------------------  
       if (TrackState &1) == 1 then
           Folder = 1
       else
           Folder = 0
       end
       --------------------------------------------------------------- 
       -------------------REC-ARM TRACK-------------------------------  
       if (TrackState &64) == 64 then
           RecArm = 1
       else
           RecArm = 0
       end
       --------------------------------------------------------------- 
       -----rec arm child tracks
       if Folder == 1 and RecArm == 1 then
          FolderArm = 1
       else 
          FolderArm = 0
       end
             
  -- LOOP FOR EVERY ITEM
    for j = 0, count_items_track -1 do
        item = reaper.GetTrackMediaItem(track, j)       
      
  -- CHECK THE FIRST TAKE OF ITEM TO DETERMINE SOURCE TYPE         
        take = reaper.GetMediaItemTake(item, 0)    
        source = reaper.GetMediaItemTake_Source(take)       
        take_type = reaper.GetMediaSourceType(source, "test")                 
        _G["take_type"..j] = take_type       
     
  ---- TAKE TYPES -----------------------------------------       
          if take_type == "MIDI" then
             RTakeType = "M"
          elseif take_type == "VIDEO" then
             RTakeType = "V"         
          else
             RTakeType = "A"
          end         
    end
    
        item_check = 1 --ITEMS IN TRACK ARE CONSIDERED TO BE ALL SIMILAR
     if count_items_track >= 2  then 
    
  --CHECK IF SOME ITEMS IN TRACK DON'T MATCH
        for l = 0, count_items_track -2 do
            m = (l + 1)
          if take_type0 ~= _G["take_type"..m] then
           --  reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
             reaper.GetSetMediaTrackInfo_String(track, "P_TCP_LAYOUT", "cc --- Large Media",1)
            item_check = 0
          break
        end
     end
  end

      --IF ALL THE ITEMS MATCH CHECK THE SOURCE TYPE AND CHANGE TRACK LAYOUT
  ----------------------------TRACK HAS ITEMS ------------------------------------------
  if item_check == 1 and count_items_track > 0 and RecArm == 0 then
      ---------MIDI---------------------------------------------------------------------
     if RTakeType == "M" then
      --  reaper.BR_SetMediaTrackLayouts(track, "", "aa - Standard")
      reaper.GetSetMediaTrackInfo_String(track, "P_TCP_LAYOUT", "aa - Standard",1)
      ---------VIDEO--------------------------------------------------------------------
     elseif RTakeType == "V" then
          --  reaper.BR_SetMediaTrackLayouts(track, "", "ba - Small") 
      reaper.GetSetMediaTrackInfo_String(track, "P_TCP_LAYOUT", "ba - Small",1)    
      ---------AUDIO--------------------------------------------------------------------
     elseif RTakeType == "A" then    
       --     reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")  
       reaper.GetSetMediaTrackInfo_String(track, "P_TCP_LAYOUT", "cc --- Large Media",1)   
     end
  end
  ----------------------------TRACK HAS ITEMS ------------------------------------------
        
      ------------------------NO ITEMS -------------------------------------------------
      --------FOLDER--------------------------------------------------------------------
      if count_items_track == 0 then
      
          if Folder == 1 then
           --   reaper.BR_SetMediaTrackLayouts(track, "", "ai --- Standard Live Recording")
             reaper.GetSetMediaTrackInfo_String(track, "P_TCP_LAYOUT", "ai --- Standard Live Recording",1)
      --------AUX - HAS RECEIVES AND FX-------------------------------------------------
     --     elseif Aux == 1 then
     --         reaper.BR_SetMediaTrackLayouts(track, "", "ag --- Standard Compact")
      --------DEFAULT LAYOUT-------------------------------------------------------------
          elseif RecArm == 0 then                           
             --    reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
             reaper.GetSetMediaTrackInfo_String(track, "P_TCP_LAYOUT", "cc --- Large Media",1)
          end
      end
      ---------REC ARM LAYOUT------------------------------------------------------------  
      if count_items_track >= 0 and RecArm == 1 and Folder ~= 1 and Aux ~= 1 then
      --   reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")
       reaper.GetSetMediaTrackInfo_String(track, "P_TCP_LAYOUT", "bd --- Small Full Meter",1)     
      end            
  end
  

reaper.defer(Main)    
end

Main()
I've just commented out sws code and put native.

But something is wrong its CPU hungry as HELL! I can't even do 50-60 tracks and click anything.With old code I could put over 200 tracks and lag was very minimal

New API (it lags even more than it looks):


Old API:


BTW I'm on x64,and when any x86 plugin is active it slows down a lot,on both APIs

Last edited by Sexan; 09-02-2015 at 01:34 PM.
Sexan is offline   Reply With Quote
Old 09-02-2015, 01:52 PM   #36
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

Jeffos responded :
Quote:
Originally Posted by Jeffos View Post
If you change track layouts in a loop, you should use PreventUIRefresh(), e.g. in Lua, something like:
Code:
reaper.PreventUIRefresh(1)

for i = 0, count_tracks -1 do
  -- change track layout, etc
end

reaper.PreventUIRefresh(-1)
There will be a single UI update (instead of count_tracks UI updates).
But have no CLUE how to use it
Sexan is offline   Reply With Quote
Old 09-02-2015, 02:03 PM   #37
swiiscompos
Human being with feelings
 
swiiscompos's Avatar
 
Join Date: Mar 2011
Location: London
Posts: 1,211
Default

I guess you have to use reaper.PreventUIRefresh(-1) at the very end of the Main() function. I would put it just before reaper.defer() as you suggested.

EDIT: I just tested. I think there is also a mistake in the code. I will check that when I'm home.
swiiscompos is offline   Reply With Quote
Old 09-02-2015, 03:38 PM   #38
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

I have an idea that will simplify layout choosing , it won't require to open the script and write every layout that you want to use.
We will read it from reaper.ini and there are :
layout_tcp
layout_mcp
layoutaction0=sel:tcp
layoutaction1=sel:mcp
etc

So when you change the layout from Screen/Layout window it will change here
Sexan is offline   Reply With Quote
Old 09-03-2015, 01:20 AM   #39
Jeffos
Mortal
 
Jeffos's Avatar
 
Join Date: Dec 2008
Location: France
Posts: 1,969
Default

(Untested) CPU friendlier mod:

Code:
defer_cnt=0

function cooldown()
  if defer_cnt >= 10 then -- run Main() every ~300ms
    defer_cnt=0
    reaper.PreventUIRefresh(1)
    Main()
    reaper.PreventUIRefresh(-1)
  else
    defer_cnt=defer_cnt+1
  end
  reaper.defer(cooldown)
end


function Main() 
  -- COUNT TRACKS
  count_tracks = reaper.CountTracks(0)
 
  -- LOOP FOR EVERY TRACK
  for i = 0, count_tracks -1 do
      track = reaper.GetTrack(0, i)
      cur=""
      retval, cur = reaper.GetSetMediaTrackInfo_String(track, "P_TCP_LAYOUT", cur, 0)
      retval, TrackState = reaper.GetTrackState(track)
      count_items_track = reaper.CountTrackMediaItems(track)      
      receive = reaper.GetTrackNumSends(track, -1)     
      
      ----------------TRACK HAS RECEIVES ? ----------------------------      
        if receive > 0 then
           HasReceive = 1
        else
           HasReceive = 0
        end
      -------------------TRACK STATES---------------------------------
      -------------------AUX TRACK-----------------------------------  
       -- if HasReceive == 1 and (TrackState &4) == 4 then
       --    Aux = 1
      --  else
      --     Aux = 0
      --  end
       --------------------------------------------------------------- 
       -------------------FOLDER TRACK--------------------------------  
       if (TrackState &1) == 1 then
           Folder = 1
       else
           Folder = 0
       end
       --------------------------------------------------------------- 
       -------------------REC-ARM TRACK-------------------------------  
       if (TrackState &64) == 64 then
           RecArm = 1
       else
           RecArm = 0
       end
       --------------------------------------------------------------- 
       -----rec arm child tracks
       if Folder == 1 and RecArm == 1 then
          FolderArm = 1
       else 
          FolderArm = 0
       end
             
  -- LOOP FOR EVERY ITEM
    for j = 0, count_items_track -1 do
        item = reaper.GetTrackMediaItem(track, j)       
      
  -- CHECK THE FIRST TAKE OF ITEM TO DETERMINE SOURCE TYPE         
        take = reaper.GetMediaItemTake(item, 0)    
        source = reaper.GetMediaItemTake_Source(take)       
        take_type = reaper.GetMediaSourceType(source, "test")                 
        _G["take_type"..j] = take_type       
     
  ---- TAKE TYPES -----------------------------------------       
          if take_type == "MIDI" then
             RTakeType = "M"
          elseif take_type == "VIDEO" then
             RTakeType = "V"         
          else
             RTakeType = "A"
          end         
    end
    
        item_check = 1 --ITEMS IN TRACK ARE CONSIDERED TO BE ALL SIMILAR
     if count_items_track >= 2  then 
    
  --CHECK IF SOME ITEMS IN TRACK DON'T MATCH
        for l = 0, count_items_track -2 do
            m = (l + 1)
          if take_type0 ~= _G["take_type"..m] and cur ~= "cc --- Large Media" then
           --  reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
             reaper.GetSetMediaTrackInfo_String(track, "P_TCP_LAYOUT", "cc --- Large Media",1)
            item_check = 0
          break
        end
     end
  end

      --IF ALL THE ITEMS MATCH CHECK THE SOURCE TYPE AND CHANGE TRACK LAYOUT
  ----------------------------TRACK HAS ITEMS ------------------------------------------
  if item_check == 1 and count_items_track > 0 and RecArm == 0 then
      ---------MIDI---------------------------------------------------------------------
     if RTakeType == "M" and cur ~= "aa - Standard" then
      --  reaper.BR_SetMediaTrackLayouts(track, "", "aa - Standard")
      reaper.GetSetMediaTrackInfo_String(track, "P_TCP_LAYOUT", "aa - Standard",1)
      ---------VIDEO--------------------------------------------------------------------
     elseif RTakeType == "V" and cur ~= "ba - Small" then
          --  reaper.BR_SetMediaTrackLayouts(track, "", "ba - Small") 
      reaper.GetSetMediaTrackInfo_String(track, "P_TCP_LAYOUT", "ba - Small",1)    
      ---------AUDIO--------------------------------------------------------------------
     elseif RTakeType == "A" and cur ~= "cc --- Large Media" then    
       --     reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")  
       reaper.GetSetMediaTrackInfo_String(track, "P_TCP_LAYOUT", "cc --- Large Media",1)   
     end
  end
  ----------------------------TRACK HAS ITEMS ------------------------------------------
        
      ------------------------NO ITEMS -------------------------------------------------
      --------FOLDER--------------------------------------------------------------------
      if count_items_track == 0 then
          if Folder == 1 and cur ~= "ai --- Standard Live Recording" then
           --   reaper.BR_SetMediaTrackLayouts(track, "", "ai --- Standard Live Recording")
             reaper.GetSetMediaTrackInfo_String(track, "P_TCP_LAYOUT", "ai --- Standard Live Recording",1)
      --------DEFAULT LAYOUT-------------------------------------------------------------
          elseif RecArm == 0 and cur ~= "cc --- Large Media" then                           
             --    reaper.BR_SetMediaTrackLayouts(track, "", "cc --- Large Media")
             if cur ~= "ai --- Standard Live Recording" then
               reaper.GetSetMediaTrackInfo_String(track, "P_TCP_LAYOUT", "cc --- Large Media",1)
             end
          end
      end
      ---------REC ARM LAYOUT------------------------------------------------------------  
      if count_items_track >= 0 and RecArm == 1 and Folder ~= 1 and Aux ~= 1 and cur ~= "bd --- Small Full Meter" then
      --   reaper.BR_SetMediaTrackLayouts(track, "", "bd --- Small Full Meter")
       reaper.GetSetMediaTrackInfo_String(track, "P_TCP_LAYOUT", "bd --- Small Full Meter",1)     
      end            
  end  
end

cooldown()
i.e. cool down the processing frequency (~300ms is well enough for this kind of things), make use of PreventUIRefresh() to factorize UI updates, make sure the current layout has actually changed before updating it.

Last edited by Jeffos; 09-03-2015 at 06:14 AM. Reason: fixed compil error
Jeffos is offline   Reply With Quote
Old 09-03-2015, 04:48 AM   #40
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

There is an error in this line :

bad argument #3 to 'GetSetMediaTrackInfo_String' (string expected, got nil)
Code:
retval, cur = reaper.GetSetMediaTrackInfo_String(track, "P_TCP_LAYOUT", cur, 0)
?
Sexan 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 12:35 AM.


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