procedure PlayToEnd(Reset,Selection:Boolean);
var
   i,x1,x2   : integer;
   r1,r2 : TRegion;
begin
Editor.GetSelectionS(x1,x2);

if Reset then 
  for i := 0 to EditorSample.RegionCount-2 do
    begin
    r1:=EditorSample.GetRegion(i);
    r2:=EditorSample.GetRegion(i+1);
    if not Selection then
      r1.SampleEnd:=r2.SampleStart-1
    else
      if (r1.SampleStart>x1-1) and (r1.SampleStart<x2) then
        r1.SampleEnd:=r2.SampleStart-1;
    end
else
  for i := 0 to EditorSample.RegionCount-1 do 
    begin
    r1:=EditorSample.GetRegion(i);
    if not Selection then
      r1.SampleEnd:=EditorSample.Length-1
    else
      if (r1.SampleStart>x1-1) and (r1.SampleStart<x2) then
        r1.SampleEnd:=EditorSample.Length-1;
    end;
end;


var Form:TScriptDialog;

Begin
Form:=CreateScriptDialog('Play To End','Converts all markers to regions ending at the end of the sample. If Selection is activated, only selected regions will be processed.');

Form.AddInputCombo('Reset','No,Yes',0);
Form.AddInputCombo('Selection','No,Yes',0);
if Form.Execute then PlayToEnd(Form.GetInputValueAsInt('Reset')=1,Form.GetInputValueAsInt('Selection')=1);
Form.Free;
End.
