Community Forums Archive

Go Back

Subject:Guidance for Acid Test.cs
Posted by: luces1
Date:5/23/2005 7:40:29 PM

Hello again. I am hoping to get some guidance with this whole scripting business. What I would REALLY like to achieve is...

I would like to be able to set the Acid Properties (file type,beats,tempo) using the Batch converter(obviously I want to do multiple files). Is this possible? I have been looking at the AcidTest.cs as a template because it was suggested on the Forge forum that I do so. My question is..what do I do? I am looking at all these lines of code and ,well, I am not even a decent amateur programmer: for example,what should I put in the DPF(" Type {0}", acid.Type); line? What should the value be and what variable in this line gets replaced by that value? This same question applies to ALL of the command lines. I have tried to read the HELP file, but to be honest, it doesn't seem clear to me. It only states that, yea, you can do this stuff, but it doesn't seem to give any good examples of what they are describing ,IMHO.

So with allof this said, what do I do? And if someone is kind enough to respond, please let me know if I need to "Save As" the script,or do I complile it first or what. A descriptive order of the chain would be MOST appreciated!!!!! Thanks to all who reply!!!!! luces

Message last edited on5/23/2005 7:42:25 PM byluces1.
Subject:RE: Guidance for Acid Test.cs
Reply by: _TJ
Date:5/24/2005 3:12:20 PM

Sorry, The batch converter does not support setting ACID properties. The source is available, and could be modified for that purpose, but that would actually entail writing more code than just having a simple script that did the job.

The "Acid Test.cs" script doesn't do anything. But it does show you how to get and set ACID properties for a file. To get a fully functioning script, you would need to combine this code with some other script that did basic open/save operations on a set of files.

The MergeWavIntoAVI.cs that was posted earlier to this forum shows how to process all of the files in a given folder. Or the SuperMultiRender.cs script in the SDK, which shows how to process all of the currently open files.

Incidently DPF has nothing to do with any of this, if you scroll down to the bottom of the script, you will see that DPF is a function (actually a set of 4 functions) that are defined in the script.


public static void DPF(string sz) { ForgeApp.OutputText(sz); }
public static void DPF(string fmt, object o) { ForgeApp.OutputText(String.Format(fmt,o)); }
public static void DPF(string fmt, object o, object o2) { ForgeApp.OutputText(String.Format(fmt,o,o2)); }
public static void DPF(string fmt, object o, object o2, object o3) { ForgeApp.OutputText(String.Format(fmt,o,o2,o3)); }


which in turn just call the IScriptableApp method OutputText.

So basically, when you run the script "Acid Test.cs" it will print the current ACID properties to the output window. (the output window is the window at the bottom of the script editor).

In my next post. I'll walk you through the process of creating a simple script.

tj






Subject:RE: Guidance for Acid Test.cs
Reply by: _TJ
Date:5/24/2005 3:50:34 PM

Ok, so lets actually walk through the process of creating a script that sets ACID properties. This is the way I actually do it, although it is certainly not the only way.

First off, we need a blank script template to work in. So we open the script editor window (I usually leave it docked at the bottom of the Sound Forge window). And hit the New Script Template button. That gives us this:


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

public class EntryPoint {
public void Begin(IScriptableApp app) {

/*begin here*/


}

public void FromSoundForge(IScriptableApp app) {
ForgeApp = app; //execution begins here
app.SetStatusText(String.Format("Script '{0}' is running.", Script.Name));
Begin(app);
app.SetStatusText(String.Format("Script '{0}' is done.", Script.Name));
}
public static IScriptableApp ForgeApp = null;
public static void DPF(string sz) { ForgeApp.OutputText(sz); }
public static void DPF(string fmt, object o) { ForgeApp.OutputText(String.Format(fmt,o)); }
public static void DPF(string fmt, object o, object o2) { ForgeApp.OutputText(String.Format(fmt,o,o2)); }
public static void DPF(string fmt, object o, object o2, object o3) { ForgeApp.OutputText(String.Format(fmt,o,o2,o3)); }
} //EntryPoint


Next, we replace the text /*begin here*/ with our script. Assuming that we want to process all of the open files, we add this:


foreach (ISfFileHost file in app.Files)
{
// process each file here
}


the "foreach" indicates we want to loop through all of the files in app.Files, and do the operations inside the {} (which is nothing yet, // indicates a comment). While we are inside the {} the variable file, which is of type ISfFileHost will reference which file we are operating on. (i.e. the code in {} will be executed once for each file in app.Files and the value of the variable 'file' will change at each iteration to represent the file to be processed.)

To set the ACID properties for the given file, we just have to do this to make it an 8 beat loop:

// create new ACID properties object
ISfFileAcidInfo acid = new SfFileAcidInfo();
acid.Type = ACIDLoopType.Loop;
acid.BeatCount = 8;
acid.RootNote = 60; // 60 is MIDI middle C
acid.IsPitched = true;
acid.Tempo = 144.0;

// replace current ACID properties of the file with our new object
file.ACID = acid;

or this to make it a one shot.

// create new ACID properties object
ISfFileAcidInfo acid = new SfFileAcidInfo();
acid.Type = ACIDLoopType.Oneshot;
acid.BeatCount = 0;
acid.IsPitched = false;

// replace current ACID properties of the file with our new object
file.ACID = acid;

and then, finally, if you want to save the changes right away. you would add

file.Save(SaveOptions.PromptIfNoFilename);

and to close the file

file.Close(0);

add it all together, and you get the following code as a replacment for /*begin here*/

foreach (ISfFileHost file in app.Files)
{
// create new ACID properties object
ISfFileACIDInfo acidCurrent = file.ACID;
ISfFileACIDInfo acid = new SfFileACIDInfo();
acid.Type = ACIDLoopType.Oneshot;
acid.BeatCount = 0;

// replace current ACID properties of the file with our new object
file.ACID = acid;

// save and close the file.
file.Save(SaveOptions.PromptIfNoFilename);
file.WaitForDoneOrCancel();
file.Close(0);
}


Message last edited on5/24/2005 3:52:54 PM by_TJ.
Subject:RE: Guidance for Acid Test.cs
Reply by: _TJ
Date:5/24/2005 3:57:50 PM

You don't have to "Save As" a script in order to run it from the Script Editor, just hit the "Run Script" button. However, I do recommend that you always save a script before you run it. Otherwise it can be easy to forget that you never saved it and end up loosing your script. (We don't force you to save a script when you shut down Sound Forge).

tj

Subject:RE: Guidance for Acid Test.cs
Reply by: luces1
Date:5/24/2005 6:37:48 PM

Thank you!Thank you!Thank you!Thank you!Thank you!Thank you!Thank you!Thank you!Thank you!Thank you!Thank you!Thank you!

This is much better than I hoped for!!! I will take this info and start scripting straight away. This is certainly the type of guidance I was looking for!

Thank you!Thank you!Thank you!Thank you!Thank you!Thank you!
luces

Go Back