Old 10-22-2014, 08:59 PM   #1
cheyrn
Human being with feelings
 
Join Date: Oct 2014
Posts: 67
Default Paste into selected track? Part of copying regions

Here is an attempt at a script. I'm trying to copy loops of regions and put the loops into separate tracks:

Code:
selected = CountSelectedTracks(0);

rc = 1;
selected != 1 ? (
  ShowConsoleMsg("One and only one track must be selected");
  rc = 0;
);

selected_track = GetSelectedTrack(0, 0);

i = 0;
while (rc != 0) (
  rc = EnumProjectMarkers(i, is_region, marker_start, marker_end, marker_name, region_index);
  is_region ? (
    GetSet_LoopTimeRange(1, 1, marker_start, marker_end, 1);
    Main_OnCommand(40014, 0); // copy loop
    Main_OnCommand(40297, 0); // unselect all tracks
    track_num = GetNumTracks();
    InsertTrackAtIndex(track_num, 1);
    TrackList_AdjustWindows(0);
    SetTrackSelected(GetTrack(0, track_num), 1);
    TrackList_AdjustWindows(0);
    SetEditCurPos(0, 1, 0);
    TrackList_AdjustWindows(0);
    Main_OnCommand(40058, 0); // paste
    SetTrackSelected(selected_track, 1);
  );
  i = i + 1;
);
All of the TrackList_AdjustWindows invocations are there because it seemed like I had to do that in order for the following function to work.

Now, when it pastes, it is not pasting into the selected track. Do I need to be sleeping between functions? Maybe that is what adjustwindows was accomplishing. Or what do you think the problem is?
cheyrn is offline   Reply With Quote
Old 10-22-2014, 10:31 PM   #2
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

just because you set a track to be selected doesn't mean it was the "last touched track" which "paste items" depends on. A workaround is to insert a track with an action, undo/redo (then it becomes last touched), then continue the script. Sounds like a bug though.

Code:
selected = CountSelectedTracks(0);

rc = 1;
selected != 1 ? (
  ShowConsoleMsg("One and only one track must be selected");
  rc = 0;
);

i=0;
while (rc != 0) (
  rc = EnumProjectMarkers(i, is_region, marker_start, marker_end, marker_name, region_index);
  is_region ? (
  	Main_OnCommand(40297, 0); // unselect all tracks
    GetSet_LoopTimeRange(1, 1, marker_start, marker_end, 1);
    Main_OnCommand(40717, 0); // select items in time selection
    Main_OnCommand(40014, 0); // copy loop    
    SetTrackSelected(GetTrack(0, GetNumTracks()-1), 1);
    Main_OnCommand(40029, 0); // undo
    Main_OnCommand(40030, 0); // redo
    Main_OnCommand(40001, 0); //insert track
    SetEditCurPos(0, 1, 0);
    Main_OnCommand(40058, 0); // paste
  );
  i+=1;
);
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 10-22-2014, 10:44 PM   #3
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

Wait, are you trying to get all media item content within every region onto the selected track?

are you trying to have items like this:
[][][][][] <-- this could run into your inteded region

or like this?:
[]
[]
[]
[]
[]
^ this will cause tracks to be created when you run the "paste" action, inserting tracks inbetween other tracks
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 10-22-2014, 11:21 PM   #4
cheyrn
Human being with feelings
 
Join Date: Oct 2014
Posts: 67
Default

The later.

I want to only copy loops from the selected track though. If I don't select the track again it seems to go bonkers after the first loop.

Also, if there are no items selected it says it can't find anything to make a loop out of if I use copy loop.

GetNumTracks() - 1 results in it pasting before the last track. I don't follow why that is the case but removing - 1 changed that.

This seems to be working but it's adding an addition loop from somewhere:

Code:
selected = CountSelectedTracks(0);

rc = 1;
selected != 1 ? (
  ShowConsoleMsg("One and only one track must be selected");
  rc = 0;
);

selected_track = GetSelectedTrack(0, 0);

i = 0;
while (rc != 0) (
  rc = EnumProjectMarkers(i, is_region, marker_start, marker_end, marker_name, region_index);
  is_region ? (
    GetSet_LoopTimeRange(1, 1, marker_start, marker_end, 1);
    Main_OnCommand(40014, 0); // copy loop
    Main_OnCommand(40029, 0); // undo
    Main_OnCommand(40030, 0); // redo
    Main_OnCommand(40001, 0); // insert track
    Main_OnCommand(40297, 0); // unselect all tracks
    SetTrackSelected(GetTrack(0, GetNumTracks()), 1);
    SetEditCurPos(0, 1, 0);
    Main_OnCommand(40058, 0); // paste
    SetTrackSelected(selected_track, 1);
    Main_OnCommand(40421, 0); // select all items in track
  );
  i += 1;
);
cheyrn is offline   Reply With Quote
Old 10-22-2014, 11:51 PM   #5
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

The extra loop is because... if we have 3 regions
Code:
Did region return 0?
   region = 1
   do stuff   
Did region return 0?
   region = 2
   do stuff
Did region return 0?
   do stuff
   region = 3
Did region return 0?
   region = 0
   do stuff
Did region return 0? BREAK
See, with that while loop you are asking if the region exists BEFORE it has a chance to say it doesn't exist. The region does not exist and it does not overwrite marker_start, marker_end variables. It does not overwrite "is_region". So it "does stuff" one more time. If the marker doesn't exist, it doesn't update any variables.

make these changes to your code:
Code:
while (rc) (
Code:
is_region && rc ? (
Edit: '!= 0' is almost the same as not having '!= 0' and 'variable > 0 ?' is also redundant. I think if you are working with positive AND negative numbers, I think negative numbers return false.
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template

Last edited by Argitoth; 10-22-2014 at 11:59 PM.
Argitoth is offline   Reply With Quote
Old 10-23-2014, 01:26 AM   #6
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

omg why... it's 1:30 in the morning, I was supposed to be getting work done, instead I'm playing the "scripting puzzle game." Dam, as addicting as candy crush.

PHP Code:
function COPY_LOOP()            (Main_OnCommand(400140));
function 
INSERT_TRACK()         (Main_OnCommand(40001,0));
function 
PASTE()                (Main_OnCommand(400580));
function 
SELECT_ITEMS_IN_LOOP() (Main_OnCommand(407170));
function 
UNDO_REDO()            (Main_OnCommand(40029,0);Main_OnCommand(40030,0));
function 
UNSELECT_ITEMS()       (Main_OnCommand(40289,0));
function 
UNSELECT_TRACKS()      (Main_OnCommand(402970));

CountSelectedTracks(0) != ShowConsoleMsg("One and only one track must be selected"):(
  
selected_track GetSelectedTrack(00);
  
i=0;rc=1;
  while (
rc) (
    
rc EnumProjectMarkers(iis_regionmarker_startmarker_endmarker_nameregion_index);
    
is_region && rc ? (
      
GetSet_LoopTimeRange(11marker_startmarker_end1);
      
UNSELECT_ITEMS();
      
SELECT_ITEMS_IN_LOOP();

      
x=0;break=1;
      while(break && 
x<CountSelectedMediaItems(0)) (
        
current_item GetSelectedMediaItem(0x);
        
GetMediaItem_Track(current_item) == selected_track ? (item current_item; break=0);
        
x+=1;
      );

      
UNSELECT_ITEMS();
      
SetMediaItemSelected(item1);
      
item_start GetMediaItemInfo_Value(item"D_POSITION");
      
item_end item_start GetMediaItemInfo_Value(item"D_LENGTH");
      !break && 
item_start <= marker_start && item_end >= marker_end ? (
        
COPY_LOOP();
        
UNDO_REDO();
        
INSERT_TRACK();
        
UNSELECT_TRACKS();
        
SetTrackSelected(GetTrack(0GetNumTracks()), 1);
        
SetEditCurPos(010);
        
PASTE();
        
SetTrackSelected(selected_track1);
      );
    );
    
+= 1;
  );
); 

Here's the just of what I added to the script: Select items in time selection (which is inside the region). Now only select the item on the originally selected track. Is the item compatible with the "copy loop" action? Then you may continue. If not, skip.
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 10-23-2014, 08:59 AM   #7
cheyrn
Human being with feelings
 
Join Date: Oct 2014
Posts: 67
Default

Thanks. It appears to work.

If I understand, this makes it so that there doesn't have to be both a track and a media item selected. There was an unstated requirement that I first select the media item in the track. And the script that I posted last was failing to find anything to make a loop out of at some point while going through all of the regions.

In any case, looping through selected media items ends up selecting the correct items in the selected track.

Is item_start <= marker_start && item_end >= marker_end ever going to be false?
cheyrn is offline   Reply With Quote
Old 10-23-2014, 09:38 AM   #8
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

Ok, so the only problem with this right now is that you want to select specific media to be copied? Could the media be on different tracks or will you only be copying from one track?

Edit:
Quote:
Is item_start <= marker_start && item_end >= marker_end ever going to be false?
that prevents the annoying popup. if you have an item not "compatible" with the action, then it will be false.
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 10-23-2014, 09:51 AM   #9
cheyrn
Human being with feelings
 
Join Date: Oct 2014
Posts: 67
Default

No, I didn't want to select specific items. The script appears to accomplish what I set out to accomplish. I meant that my attempts at the script required me to have first selected the media item that the region crosses, in the selected track. This script finds the item instead.

What would an incompatible item be?
cheyrn is offline   Reply With Quote
Old 10-23-2014, 10:59 AM   #10
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

COMPATIBLE:
Code:
   (region)
   |      |
   [_item_]
   |      |

   (region)
   |      |
   [_item_|__]
   |      |

   (region)
   |      |
[__|_item_]
   |      |

   (region)
   |      |
[__|_item_|__]
   |      |
INCOMPATIBLE:
Code:
   (region)
   |      |
[__|_item]|
   |      |

   (region)
   |      |
   |[item]|
   |      |

   (region)
   |      |
   |[item_|__]
   |      |
Edit: Well, midi items are incompatible. If you want, you could check if the item is midi and add that to the if statement
Code:
GetMediaSourceType(PCM_source* source, #typebuf)
copies the media source type ("WAV", "MIDI", etc) to typebuf
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth 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 08:24 AM.


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