Community Forums Archive

Go Back

Subject:Script to remove markers
Posted by: MyrnaLarson
Date:3/24/2005 8:39:54 AM

I am looking for a script, preferably in VB, but C# will do, to remove markers added by running the Detect Clipping command. These marker names all begin with the work Clip.

I think I can modify one of the sample scripts (Save Regions as Files by deleting the irrelevant sections), but I don't know what the commands are to (a) check that marker name begins with "Clip" and (b) to delete that marker.

Any help would be appreciated. I would like to have the script as a script rather than a dll, so I can learn from it and not have to bother you folks for help.

Message last edited on3/24/2005 8:41:57 AM byMyrnaLarson.
Subject:RE: Script to remove markers
Reply by: jetdv
Date:3/24/2005 9:52:38 AM

Take the code you found, modify it as needed. Take the code found here where I show how to delete a specific region and modify it as needed. Combine the two to get what you need.

NOTE: When deleting multiple markers, you really need to go through the list of markers BACKWARDS - otherwise things get really confused. My example goes forwards but stops immediately after deleting the desired marker.

Subject:RE: Script to remove markers
Reply by: MyrnaLarson
Date:3/24/2005 10:05:28 AM

Thanks VERY MUCH for the Help. But this raises a couple more questions:

1) I want to operate on the already-open file. What do I modify to do that?
2) How do you specify that the marker name BEGINS with certain text. I don't know the fulll marker name. There are hundreds of them. I believe they are named "Clipping detected" followed by the time.
3) What is the code to process the collection backwards. Obviously it isn't a foreach loop. In VB I would write something like

For m = Markers.count -1 To 0 Step -1
If Markers(m).Name Like "Clip*" Then
Markers.Remove(Markers(M))
End If
Next m

Subject:RE: Script to remove markers
Reply by: jetdv
Date:3/24/2005 10:39:56 AM

1) I want to operate on the already-open file. What do I modify to do that?

Take out the for loop that goes through the file list. Set forgefile to: app.CurrentFile

2) How do you specify that the marker name BEGINS with certain text. I don't know the fulll marker name. There are hundreds of them. I believe they are named "Clipping detected" followed by the time.

If (Markers(m).Name.Substring(0,4) == "Clip") {

3) What is the code to process the collection backwards. Obviously it isn't a foreach loop. In VB I would write something like

Yes, the principle is the same. Here's a loop I have in Vegas. It will need to be modified to work correcly in SF.

for (int i=Vegas.Project.Markers.Count - 1; i >= 0; i--) {
Marker thisMarker = regMarkers as Marker;
// process the marker in some way as needed such as deleting it.
}

Subject:RE: Script to remove markers
Reply by: MyrnaLarson
Date:3/24/2005 10:50:29 AM

Thanks! With your help, I think I may get this working!

Subject:RE: Script to remove markers
Reply by: MyrnaLarson
Date:3/24/2005 10:54:13 AM

PS: In case anybody is reading this an wondering why I want to remove the Clipping markers, it's because I have already used the Clipped Peak Restoration routine that is part of Noise Reduction to fix the clips and they aren't clipped any more.

Subject:RE: Script to remove markers
Reply by: MyrnaLarson
Date:3/25/2005 5:38:44 PM

I wanted to report back that, thanks to the help I received here, I got my script to remove the "Clip detected" markers working!

Subject:RE: Script to remove markers
Reply by: jetdv
Date:3/25/2005 6:14:57 PM

Glad to hear you got it working. Hope I help in the process. If you'd like to share, feel free to post the final version here.

Message last edited on3/25/2005 6:16:11 PM byjetdv.
Subject:RE: Script to remove markers
Reply by: MyrnaLarson
Date:3/28/2005 7:56:31 PM

Yes, I definitely made use of the information you gave me. Wouldn't have been able to complete this job without it, in fact. Thanks!

I can post my code if you are interested. But I can't find any information on how to post it as a sort of attachment, with a link, as you did, rather than in-line.

Subject:RE: Script to remove markers
Reply by: _TJ
Date:3/29/2005 3:01:18 PM

Just post the text in a message. jetdv hosts the links on his own site which is how he is able to link to the script rather than posting text.

tj

Subject:RE: Script to remove markers
Reply by: MyrnaLarson
Date:3/29/2005 9:43:34 PM

Thanks for the info. My script is below. I've removed stuff that (as best I could tell) I didn't need, like the GETARG and DPF procedures.

using System;
using System.IO;
using System.Windows.Forms;
using SoundForge;

//Run with a file open that contains markers set by Detect Clipping
//Uses an undo wrapper, so that you can redo all markers in one step

public class EntryPoint
{
public string Begin(IScriptableApp app)
{
// no arguments
ISfDataWnd wnd = app.ActiveWindow;
if (null == wnd)
{
return "Open a file containing clipping markers before running this script.";
}

ISfFileHost file = app.CurrentFile;

// create undo wrapper: just one undo for whole operation
string szUndo = "Remove Clip Markers";
int idUndo = file.BeginUndo(szUndo);

string LabelPrefix = "Clip Detected ";
int PrefixLen = LabelPrefix.Length;

int n = file.Markers.Count;
int removed = 0;

for (int i=n-1; i>=0; i--)
{
SfAudioMarker mk = file.Markers;
if ((mk.Name.Length >=PrefixLen) && (mk.Name.Substring(0,PrefixLen) == LabelPrefix))
{
file.Markers.Remove(mk);
removed++;
}
}

// close undo wrapper and keep changes
file.EndUndo(idUndo, false);

return String.Format("{0} clip markers removed of {1} total markers in file.", removed, n);

} //Begin

public void FromSoundForge(IScriptableApp app)
{
// execution begins with next line
// NB: Script.Name is null if script has been changed but not explicitly saved before running
app.SetStatusText(String.Format("Script '{0}' is running.", Script.Name));
string szMessage = Begin(app);
app.SetStatusText((szMessage != null) ? szMessage : String.Format("Script '{0}' is done.", Script.Name));
} //FromSoundForge

} //EntryPoint

Subject:RE: Script to remove markers
Reply by: _TJ
Date:3/30/2005 6:34:57 PM

Thanks. just FYI you can use the html PRE tag around your code
to prevent it from getting reformatted. (thanks to jetdv for the tip!)

--------------------------- code ---------------------------

using System;
using System.IO;
using System.Windows.Forms;
using SoundForge;

//Run with a file open that contains markers set by Detect Clipping
//Uses an undo wrapper, so that you can redo all markers in one step

public class EntryPoint
{
public string Begin(IScriptableApp app)
{
// no arguments
ISfDataWnd wnd = app.ActiveWindow;
if (null == wnd)
{
return "Open a file containing clipping markers before running this script.";
}

ISfFileHost file = app.CurrentFile;

// create undo wrapper: just one undo for whole operation
string szUndo = "Remove Clip Markers";
int idUndo = file.BeginUndo(szUndo);

string LabelPrefix = "Clip Detected ";
int PrefixLen = LabelPrefix.Length;

int n = file.Markers.Count;
int removed = 0;

for (int i=n-1; i>=0; i--)
{
SfAudioMarker mk = file.Markers;
if ((mk.Name.Length >=PrefixLen) && (mk.Name.Substring(0,PrefixLen) == LabelPrefix))
{
file.Markers.Remove(mk);
removed++;
}
}

// close undo wrapper and keep changes
file.EndUndo(idUndo, false);

return String.Format("{0} clip markers removed of {1} total markers in file.", removed, n);

} //Begin

public void FromSoundForge(IScriptableApp app)
{
// execution begins with next line
// NB: Script.Name is null if script has been changed but not explicitly saved before running
app.SetStatusText(String.Format("Script '{0}' is running.", Script.Name));
string szMessage = Begin(app);
app.SetStatusText((szMessage != null) ? szMessage : String.Format("Script '{0}' is done.", Script.Name));
} //FromSoundForge

} //EntryPoint

------------------------------ end of code -------------------------------------

Subject:RE: Script to remove markers
Reply by: _TJ
Date:3/30/2005 6:50:00 PM

Good script. This would be a good one to have in the set of sample scripts.

You are correct that you don't need the DPF and GETARG procedures in this script. Those precedures are just there to make it easier to test and debug scripts in the Script Editor window.

It turns out that the .NET string class has an easier way to do the comparison

replace this:

if ((mk.Name.Length >=PrefixLen) && (mk.Name.Substring(0,PrefixLen) == LabelPrefix))

with this

if (mk.Name.StartsWith(LabelPrefix))




Subject:RE: Script to remove markers
Reply by: MyrnaLarson
Date:3/31/2005 1:46:40 PM

> It turns out that the .NET string class has an easier way to do the comparison

Thanks for that info. Yes, that's certainly easier, and it eliminates the need for a variable (the length). I will modify the code to implement it.

Do you have any information as to when the documentation re the object model will be available (i.e. the SDK mentioned in the SF8 Manual)? Will it include this kind of information? If not, where do you suggest that a person look for it?

You are free to include the script in your samples if you like.


Subject:RE: Script to remove markers
Reply by: jetdv
Date:3/31/2005 2:03:25 PM

If not, where do you suggest that a person look for it?

Here's a starting point.

Message last edited on3/31/2005 2:03:42 PM byjetdv.
Subject:RE: Script to remove markers
Reply by: _TJ
Date:3/31/2005 3:41:18 PM

The documentation for the Sound Forge object model should be out soon, but as for information like what I just shared with you, you can only learn that by browsing the .NET framework or by reading other people's code. I have yet to see a good searchable reference that doesn't depend on you already having a pretty good idea what the possible options are.

You can learn a lot about the Sound Forge object model by using a class browser. There's one built into Visual Studio .NET, you can use the .NET reflector available from aristo.com

http://www.aisto.com/roeder/dotnet/

look around in Forge80.Script.dll using the reflector, and pay special attention to ISfFileHost and IScriptableApp interfaces and the objects that you can
get to from there.

Be avised that reflector will show you ALL of the methods, including those that are for internal use only, or that are not yet implemented.

With that said, it's still a great way to learn your way around.

tj



Subject:RE: Script to remove markers
Reply by: MyrnaLarson
Date:3/31/2005 7:35:33 PM

I am reasonably proficient in Visual Basic (I've been programming in Basic since 1977, on the Apple II). It would certainly be helpful if Sony would provide some sample scripts written in VB as well as C#.

Subject:RE: Script to remove markers
Reply by: _TJ
Date:4/1/2005 4:41:31 PM

We are pretty weak on VB programming expertise here, but I agree that having VB examples would be a good thing.

On the other If you plan to write more than a few scripts, you would do well to learn C#. Once you know one programming language, picking up another is generally a matter of just a few days.

the C# compiler is much more likely to find bugs at compile time rather than at runtime, which can safe you a lot of time in the long run.

tj

Go Back