GetSetItemState Notes pl

From CockosWiki

Jump to: navigation, search

GetSetItemStateNotes.pl

#
# GetSetItemState_Notes.pl
#
# Inserts notes in an item, doesn't work well if the item already has notes...
#
 
use strict;
use warnings;
 
use constant CURR_PROJ => 0;
 
my ($bool, $it, $chunk, $maxlen);
 
my $length = -1;
my $result = "fail";
 
# Get the first selected item in the current project
$it = RPR_GetSelectedMediaItem(CURR_PROJ, 0);
 
# set-up for call to GetSetItemState
$chunk="";     # Get, not Set
$maxlen=2048;  # max num of chars to return
 
# Get the ItemState
($bool, $it, $chunk, $maxlen) = RPR_GetSetItemState($it, $chunk, $maxlen);
$result = "pass" if $bool;
RPR_ShowConsoleMsg("GetSetItemState reports $result\n$chunk\n");
 
# some notes
my $notes = "<NOTES
|Bottom line is I would like to be able to use my Control 24 with
|Reaper, or at least partially (motorized faders, S, M, R, buttons,
|etc.). Now for those of you unfamiliar with it, the Control 24 does
|not use any known standard way of communicating with the DAW;
|instead it is proprietary and specific to Pro Tools. That said,
|some initial investigation into the way it communicates leads me
|to believe there is hope (more on this later).
>\n";
 
# insert them after the IGUID line
$chunk =~s/(IGUID.*}\n)/$1$notes/;
 
# Set the ItemState
$result = "fail";
($bool, $it, $chunk, $maxlen) = RPR_GetSetItemState($it, $chunk, $maxlen);
$result = "pass" if $bool;
RPR_ShowConsoleMsg("AFTER SET: GetSetItemState reports $result\n$chunk\n");


sub InsertNotesInItem($)

Also, a subroutine to insert notes.

sub InsertNotesInItem($){ my ($text) = @_; # the text to be inserted as a note
 
  my @text_split = (); # where multiline text lives until we build the text block to be inserted
  my $notes = ();      # where we'll place the finished data to be inserted in to the item
  my $delimiter = "\n";
  my ($bool, $it, $chunk, $maxlen);
  my $z;
 
  my $length = -1;
  my $result = "fail";
 
# Build the notes block
 
  @text_split = split(/$delimiter/, $text);	# split the text in to lines
  chomp @text_split;
 
  $notes = "<NOTES\n";
  for ($z=0;$z<scalar(@text_split);$z++){
    $notes = $notes . "|" . $text_split[$z] . "\n";
  }
  $notes = $notes . ">\n";
 
# Get the first selected item in the current project
  $it = RPR_GetSelectedMediaItem(CURR_PROJ, 0);
 
# set-up for call to GetSetItemState
  $chunk="";     # Get, not Set
  $maxlen=2048;  # max num of chars to return
 
# Get the ItemState
  ($bool, $it, $chunk, $maxlen) = RPR_GetSetItemState($it, $chunk, $maxlen);
  if($bool){
    #RPR_ShowConsoleMsg("GetSetItemState reports $result\n$chunk\n");
 
    # insert them after the IGUID line
    $chunk =~s/(IGUID.*}\n)/$1$notes/;
 
    # Set the ItemState
    $result = "fail";
    ($bool, $it, $chunk, $maxlen) = RPR_GetSetItemState($it, $chunk, $maxlen);
  }
  return($bool);
}
Personal tools