Old 03-22-2014, 07:10 PM   #1
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Phoenix, AZ
Posts: 2,055
Default How do you glue/render items with ReaScript?

Is there a way to glue items with ReaScript? I need to glue large sets of items. Looping through items and gluing doesn't seem to work because REAPER won't glue items if the script is moving too fast... at least I think that's why it's not working.
__________________
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 03-23-2014, 06:14 AM   #2
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,161
Default

I gather you make sample libraries and such consisting of many audio items? I made a looping glue script because I use lots of small MIDI items when composing. It works in that respect. Does your script work if you use it on on MIDI items? I'm sure my script is not a model one, but I'll post it later if you're interested.
FnA is offline   Reply With Quote
Old 03-23-2014, 01:40 PM   #3
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Phoenix, AZ
Posts: 2,055
Default

Yes, if you have a script that demonstrates gluing, that would be great!
__________________
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 03-23-2014, 02:29 PM   #4
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,161
Default

This is the only one I have on my laptop at the moment.

Edited version a few posts down. Minor speed improvement.

Code:
###glue all selected items to themselves-retaining color-reselect###
from reaper_python import *
from contextlib import contextmanager

@contextmanager
def undoable(message):
    RPR_Undo_BeginBlock2(0)
    try:
        yield
    finally:
        RPR_Undo_EndBlock2(0, message, -1)

with undoable("glue all selected items to themselves-RC-RS"):

    csmi = RPR_CountSelectedMediaItems(0)
    smiL = []
    gmiL = []

    for c in range(csmi):
        CurrItem = RPR_GetSelectedMediaItem(0, c)
        smiL.append(CurrItem)

    while len(smiL) >= 1:
        RPR_Main_OnCommand(40289, 0)#unselect all items
        RPR_SetMediaItemSelected(smiL.pop(), 1)

        CurrItem = RPR_GetSelectedMediaItem(0, 0)
        ATInt = int(RPR_GetMediaItemInfo_Value(CurrItem, "I_CURTAKE"))
        ActiveTake = RPR_GetMediaItemTake(CurrItem, ATInt)
        ClrList = []
        TakeClr = RPR_GetMediaItemTakeInfo_Value(ActiveTake, "I_CUSTOMCOLOR")
        if TakeClr == 0:
            ItemClr = RPR_GetMediaItemInfo_Value(CurrItem, "I_CUSTOMCOLOR")
            ClrList.append(ItemClr)
        else:
            ClrList.append(TakeClr)

        RPR_Main_OnCommand(40362, 0)#glue items ignoring time selection

        RPR_SetMediaItemInfo_Value(CurrItem, "I_CUSTOMCOLOR", ClrList[0])

        CurrItem = RPR_GetSelectedMediaItem(0, 0)
        gmiL.append(CurrItem)

    for i in range(len(gmiL)):
        RPR_SetMediaItemSelected(gmiL[i], 1)
Probably should change it to include spk77s NoUIRefresh method.

Last edited by FnA; 03-23-2014 at 06:23 PM.
FnA is offline   Reply With Quote
Old 03-23-2014, 05:45 PM   #5
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,221
Default

Quote:
Originally Posted by FnA View Post
This is the only one I have on my laptop at the moment.
shit, FnA thanks!
I have been wanting exactly one script like this one for a year. I started to learn scripting to do it but I couldn't finish anything. Now this one of yours, it is working exactly as I wanted. Even preserving colors... And you had it on your laptop all this time!!! LOL

I wonder how many other things I have missed from this great community here.

Last edited by heda; 03-23-2014 at 05:57 PM.
heda is offline   Reply With Quote
Old 03-23-2014, 06:06 PM   #6
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,161
Default

Well I was wanting it about that long ago too but have only had it written for a few months now. But I do use it constantly. I think it would be possible to preserve muted notes and maybe other events too but have not gotten around to it. Sounds like it might be somewhat in the works, but who knows, right? Just request things which you think are useful in the script request sticky. Someone might help, especially if it's something they can use as well. I don't usually come around the forum so much nowadays, but I'm away from my main writing computer for a while, and usually check in once a week anyway.

I'll adjust it with the prevent UI refresh thing. Probably will speed it up a bit.

Code:
###glue all selected items to themselves-retaining color-reselect###
from reaper_python import *
from contextlib import contextmanager

@contextmanager
def undoable(message):
    RPR_Undo_BeginBlock2(0)
    try:
        yield
    finally:
        RPR_Undo_EndBlock2(0, message, -1)

@contextmanager
def noUIRefresh():
    RPR_PreventUIRefresh(1)
    try:
        yield
    finally:
        RPR_PreventUIRefresh(-1)        

def gttsrcrs():
    csmi = RPR_CountSelectedMediaItems(0)
    smiL = []
    gmiL = []

    for c in range(csmi):
        CurrItem = RPR_GetSelectedMediaItem(0, c)
        smiL.append(CurrItem)

    while len(smiL) >= 1:
        RPR_Main_OnCommand(40289, 0)#unselect all items
        RPR_SetMediaItemSelected(smiL.pop(), 1)

        CurrItem = RPR_GetSelectedMediaItem(0, 0)
        ATInt = int(RPR_GetMediaItemInfo_Value(CurrItem, "I_CURTAKE"))
        ActiveTake = RPR_GetMediaItemTake(CurrItem, ATInt)
        ClrList = []
        TakeClr = RPR_GetMediaItemTakeInfo_Value(ActiveTake, "I_CUSTOMCOLOR")
        if TakeClr == 0:
            ItemClr = RPR_GetMediaItemInfo_Value(CurrItem, "I_CUSTOMCOLOR")
            ClrList.append(ItemClr)
        else:
            ClrList.append(TakeClr)

        RPR_Main_OnCommand(40362, 0)#glue items ignoring time selection

        RPR_SetMediaItemInfo_Value(CurrItem, "I_CUSTOMCOLOR", ClrList[0])

        CurrItem = RPR_GetSelectedMediaItem(0, 0)
        gmiL.append(CurrItem)

    for i in range(len(gmiL)):
        RPR_SetMediaItemSelected(gmiL[i], 1)

with undoable("glue all selected items to themselves-RC-RS"):
    with noUIRefresh():
        gttsrcrs()

Last edited by FnA; 03-23-2014 at 06:22 PM.
FnA is offline   Reply With Quote
Old 03-24-2014, 06:28 AM   #7
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,161
Default

Here is tentative version which preserves muted notes. Seems to be working. I'm just learning the new MIDI functions and have not gotten the hang of doing CCs yet, if anyone wants to pitch in feel free.

Code:
###glue all selected items to themselves-retaining color and muted notes-reselect###
from reaper_python import *
from contextlib import contextmanager

@contextmanager
def undoable(message):
    RPR_Undo_BeginBlock2(0)
    try:
        yield
    finally:
        RPR_Undo_EndBlock2(0, message, -1)

@contextmanager
def noUIRefresh():
    RPR_PreventUIRefresh(1)
    try:
        yield
    finally:
        RPR_PreventUIRefresh(-1)        

def gttsrcrs():
    csmi = RPR_CountSelectedMediaItems(0)
    smiL = []
    gmiL = []

    for c in range(csmi):
        CurrItem = RPR_GetSelectedMediaItem(0, c)
        smiL.append(CurrItem)

    while len(smiL) >= 1:
        RPR_Main_OnCommand(40289, 0)#unselect all items
        RPR_SetMediaItemSelected(smiL.pop(), 1)

        CurrItem = RPR_GetSelectedMediaItem(0, 0)
        ATInt = int(RPR_GetMediaItemInfo_Value(CurrItem, "I_CURTAKE"))
        ActiveTake = RPR_GetMediaItemTake(CurrItem, ATInt)
        ClrList = []
        TakeClr = RPR_GetMediaItemTakeInfo_Value(ActiveTake, "I_CUSTOMCOLOR")
        if TakeClr == 0:
            ItemClr = RPR_GetMediaItemInfo_Value(CurrItem, "I_CUSTOMCOLOR")
            ClrList.append(ItemClr)
        else:
            ClrList.append(TakeClr)

        MuteNoteL = []
        AAA = RPR_MIDI_CountEvts(ActiveTake, 0, 0, 0)

        for i in range(AAA[2]):
            CN = RPR_MIDI_GetNote(ActiveTake,i+1,0,0,0,0,0,0,0)
            if CN[4]:
                MuteNoteL.append(CN)

        RPR_Main_OnCommand(40362, 0)#glue items ignoring time selection
        CurrItem = RPR_GetSelectedMediaItem(0, 0)
        ATInt = int(RPR_GetMediaItemInfo_Value(CurrItem, "I_CURTAKE"))
        ActiveTake = RPR_GetMediaItemTake(CurrItem, ATInt)

        for n in range(len(MuteNoteL)):
            a, b, c, d, e, f = MuteNoteL[n][3], MuteNoteL[n][5], MuteNoteL[n][6], MuteNoteL[n][7], MuteNoteL[n][8], MuteNoteL[n][9]
            RPR_MIDI_InsertNote(ActiveTake, a, 1, b, c, d, e, f)

        RPR_SetMediaItemInfo_Value(CurrItem, "I_CUSTOMCOLOR", ClrList[0])

        gmiL.append(CurrItem)

    for i in range(len(gmiL)):
        RPR_SetMediaItemSelected(gmiL[i], 1)

with undoable("glue all selected items to themselves-RC-RMN-RS"):
    with noUIRefresh():
        gttsrcrs()
FnA is offline   Reply With Quote
Old 03-24-2014, 08:02 AM   #8
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Phoenix, AZ
Posts: 2,055
Default

Well, I don't know what was wrong last time I tried to use glue, but all of a suddent it's working! So I can run the glue command without problems.
__________________
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 01-24-2015, 06:10 PM   #9
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 5,867
Default

I just found this thread completly randomly, and I wanted to do this since days !
Thank you, will be very helpful, I will try to see if it can be easily converted to EEL.
EDIT : ok it's too hard for me ^^

Last edited by X-Raym; 01-24-2015 at 06:20 PM.
X-Raym is offline   Reply With Quote
Old 01-24-2015, 08:50 PM   #10
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,161
Default

Quote:
Originally Posted by X-Raym View Post
ok it's too hard for me ^^
Me too. I think maybe you might make a string and then pick away at it but I'm noob with eel. Might work to make simpler version that uses save selected items and picks, say, the first one and blablabla.
FnA is offline   Reply With Quote
Old 01-25-2015, 11:50 AM   #11
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 5,867
Default

Yep, I was thinking about it, but since a script already exist and it's developers have already faced a lot of difficulties, I think it would be easier to just "convert" the script than reinventing the wheel :P
The thing is that I don't know python at all so it is a bit hard to transcribe it. And it seems to use some things that I wouldn't be able to reproduce in EEL.

Any volunteer ?
X-Raym is offline   Reply With Quote
Old 01-25-2015, 07:48 PM   #12
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 5,867
Default

Ok I'm on it.
I rename all the variables with more understandable name and I comment every line of code.
It seem feasable in EEL, but I need to know a bit more about table/array/stack in this language before.
X-Raym is offline   Reply With Quote
Old 01-26-2015, 09:28 AM   #13
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 5,867
Default

Thanks to kuus0's help on Help : Basic Array and Table management in EEL, it started to look good !



It is pretty raw for the moment, but I will add the color conservation, muted note conservation, and try to delete this "glued" on item names :P
X-Raym is offline   Reply With Quote
Old 01-26-2015, 10:43 AM   #14
witti
Human being with feelings
 
witti's Avatar
 
Join Date: May 2012
Posts: 1,186
Default

Nice !
witti is offline   Reply With Quote
Old 01-26-2015, 06:50 PM   #15
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 5,867
Default

  • Glue -> working
  • Color -> working
  • Name conservation -> working
  • Undo point -> working
Just need to finish the muted notes part and it will be ready for sharing :P
Maybe tomorrow !

Last edited by X-Raym; 01-26-2015 at 06:56 PM.
X-Raym is offline   Reply With Quote
Old 01-27-2015, 10:05 AM   #16
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 5,867
Default EEL : Glue selected items independently

HI !

I just release my script.

here is the thread :
EEL : Glue selected items independently

It just need the "muted note" preservation to be complete, but it is already quite useful as it is !
X-Raym is offline   Reply With Quote
Old 01-27-2015, 02:27 PM   #17
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,488
Default

Quote:
Originally Posted by X-Raym View Post
HI !

I just release my script.

here is the thread :
EEL : Glue selected items independently

It just need the "muted note" preservation to be complete, but it is already quite useful as it is !
Hi!
MIDI_InsertNote is broken (in the official version(s) ), so the "muted note" preservation isn't possible at the moment.

I hope I didn't break anything - I've made some modifications ("muted note" preservation is commented out):

Code:
// Glue selected items independently
// EEL Script for Reaper
// Author : X-Raym
// Author URl : http://extremraym.com
// Source : GitHub > X-Raym > EEL Scripts for Cockos REAPER
// Source URl : https://github.com/X-Raym/REAPER-EEL-Scripts
// Licence : GPL v3
// Release Date : 26-01-2015

// Version : 0.8
// Version Date : 27-01-2015
// Required : Reaper 4.76

// ----- DEBUGGING ====>
@import X-Raym_Functions - console debug messages.eel

debug = 1; // 0 => No console. 1 => Display console messages for debugging.
clean = 1; // 0 => No console cleaning before every script execution. 1 => Console cleaning before every script execution.

msg_clean();
// <==== DEBUGGING -----

function glue_independently() local(i, item, j)
( 
  // BEGIN
  Undo_BeginBlock(); 
  countSelectedMediaItem = CountSelectedMediaItems(0);
  msg_dtl("Nombre d'objet sélectionné", countSelectedMediaItem, 0);
  
  setSelectedMediaItem = 0; // memory address
  setSelectedMediaItem_length = 0;
  
  // PUT SELECTED ITEMS IN ARRAY
  i = 0;
  msg_s("Item Selection List");
  loop(CountSelectedMediaItems(0),
    (item = GetSelectedMediaItem(0, i)) ? (
      setSelectedMediaItem[i] = item;
      msg_d(setSelectedMediaItem[i]);
      
      setSelectedMediaItem_length += 1;
    );
    i += 1;
  );
  msg_s("-----");
  
  // UNSELECT ALL ITEMS
 Main_OnCommand(40289, 0);
 
 MuteNoteL = setSelectedMediaItem_length; // memory address

  // LOOP THROUGH SELECTION
  j = 0;
  loop(setSelectedMediaItem_length,
    // CHECK THE LOOP
    msg_d(j);
  
    msg_dtl("Selection",setSelectedMediaItem[j],1);// why -1 ? Don't know but seem to work
    SetMediaItemSelected(setSelectedMediaItem[j], 1); // select current item in loop

    // GET ACTIVE TAKE
    CurrItem = setSelectedMediaItem[j];
    ActiveTake = GetActiveTake(CurrItem);

    // GET NAME
    GetSetMediaItemTakeInfo_String(ActiveTake, "P_NAME", #stringNeedBig, 0);
    activeTake_name = #stringNeedBig;

    // GET COLOR
    TakeClr = GetMediaItemTakeInfo_Value(ActiveTake, "I_CUSTOMCOLOR");
    TakeClr === 0 ? (
      ItemClr = GetMediaItemInfo_Value(CurrItem, "I_CUSTOMCOLOR");
      color = ItemClr;
    ):(
      color = TakeClr;
    );

    // GET MUTED NOTES
    MuteNoteL_length = 0;
    MIDI_CountEvts(ActiveTake, note_count, 0, 0);
    msg_dtl("Number of notes :", note_count, 1);
    
    
    ActiveTake = GetActiveTake(GetSelectedMediaItem(0,0)); // don't know if this is necessary
/*      i = 0;
    note_index = 0;
    loop(note_count,
      MIDI_GetNote(ActiveTake, note_index, selected, muted, startppqpos, endppqpos, chan, pitch, vel);
      msg_dtl("Muted state: ",muted,1);
      muted ? (
        MuteNoteL[i]   = selected;
        MuteNoteL[i+1] = muted;
        MuteNoteL[i+2] = startppqpos;
        MuteNoteL[i+3] = endppqpos;
        MuteNoteL[i+4] = chan;
        MuteNoteL[i+5] = pitch;
        MuteNoteL[i+6] = vel;
        MuteNoteL_length += 1;
        i += 7;
      );
      note_index += 1;
    ); */

    // GLUE WITHOUT TIME SELECTION
    Main_OnCommand(40362, 0);

    // RE SET NAME
    GetSetMediaItemTakeInfo_String(ActiveTake, "P_NAME", activeTake_name, 1);

    // RE SET COLOR
    SetMediaItemInfo_Value(CurrItem, "I_CUSTOMCOLOR", color);
    
/*      // RE SET NOTE
    i = 0;
    loop(MuteNoteL_length,
      a = MuteNoteL[i];
      b = MuteNoteL[i+1];
      c = MuteNoteL[i+2];
      d = MuteNoteL[i+3];
      e = MuteNoteL[i+4];
      f = MuteNoteL[i+5];
      g = MuteNoteL[i+6];
      
      MIDI_InsertNote(ActiveTake, a, b, c, d, e, f, g);
      i += 7;
    ); */

    SetMediaItemSelected(setSelectedMediaItem[j], 0); // unselect current item in loop
    j += 1;
  );
  
  // RSELECT ALL
  //--------
  Undo_EndBlock("Glue selected items independently", -1); // -1 = "Undo state all"
);

glue_independently();
UpdateArrange();
spk77 is offline   Reply With Quote
Old 01-27-2015, 02:30 PM   #18
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 5,867
Default

@spk77
There is broken functions ! How do you know this, I spend hours on it

I also commented out the insert note part on my local version so yes, I confirm, it doesn't cause any problem.

Thanks for your expertise
X-Raym is offline   Reply With Quote
Old 01-27-2015, 02:39 PM   #19
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,488
Default

Quote:
Originally Posted by X-Raym View Post
@spk77
There is broken functions ! How do you know this, I spend hours on it

I also commented out the insert note part on my local version so yes, I confirm, it doesn't cause any problem.

Thanks for your expertise
The bug is here in the bug tracker:
http://forum.cockos.com/project.php?issueid=5365
(status: fix coming soon )

Last edited by spk77; 01-27-2015 at 03:01 PM.
spk77 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 02:22 AM.


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