Community Forums Archive

Go Back

Subject:script works fine.. but crashes at end
Posted by: regex_jedi
Date:10/30/2005 4:54:08 PM

I have a regular templatized C# script (the real content of which TJ wrote all of )..

the script compiles good..
it also executes all the intended functions I need it to.

only, at the completion of the script, it always gives me a crash of Sound Forge. I changed the end of the Begin method code to use "return" with and without "null". (The begin is "void" defined as a public method). I can't seem to figure out how to get it to NOT crash when it finishes...

I know I must be just doing something simple wrong...

any clues?

regex_jedi

Subject:RE: script works fine.. but crashes at end
Reply by: jetdv
Date:10/30/2005 6:36:33 PM

Can you post the full text of the current script and the exact error message it gives?

Subject:RE: script works fine.. but crashes at end
Reply by: regex_jedi
Date:10/30/2005 9:24:30 PM

okey dokey... here it is..


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

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

// ask the user to choose a filename & directory,
// (we will add track# automatically)
//
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = "MPEG Layer 3 (*.mp3)|*.mp3";
dlg.InitialDirectory = @"C:\clips";
dlg.Title = "Choose a Folder and Base Filename";
dlg.CheckPathExists = true;
dlg.CheckFileExists = false;
dlg.DefaultExt = ".mp3";
if (DialogResult.OK != dlg.ShowDialog(null))
{
// no file chosen
return;
}
string strBaseFilename = dlg.FileName;
// ask the user to choose a MP3 template.
//
ISfRenderer rend = app.FindRenderer(null, ".mp3");
if (null == rend)
{
MessageBox.Show(app.Win32Window, "Could not find file format");
return;
}
ISfGenericPreset tpl = rend.ChooseTemplate(IntPtr.Zero, "192 Kbps, CD Transparent Audio");
// locate a CD Drive that has an Audio CD in it.
//
ISfCDDrive drvToRip = null;
foreach (ISfCDDrive drv in app.CDDrives)
{
DPF("checking {0} for an audio cd", drv.Letter);
if ((drv.DiscType & DiscType.Audio) == DiscType.Audio)
{
// found an audio cd.
drvToRip = drv;
break;
}
}
if (null == drvToRip)
{
MessageBox.Show(app.Win32Window, "Can't find an Audio CD to Rip.");
return;
}

// Now rip each track in the Audio CD to a separate file,
// and store the file objects in an array so we can use them for processing later.
//
System.Collections.ArrayList files = new System.Collections.ArrayList();
foreach (SfAudioMarker mk in drvToRip.DiscTOC.MarkerList())
{

ISfFileHost file = drvToRip.ExtractAudio(mk.Name,mk.Start,mk.Length,0);
if (null == file)
break;
if (SfStatus.Cancel == file.WaitForDoneOrCancel())
break;
file.Summary.Title = mk.Name;
file.Summary.TrackNo = mk.Ident.ToString();
files.Add(file);
}

foreach (ISfFileHost file in files)
{
file.DoEffect("Auto Region", "16bars", SfAudioSelection.All, EffectOptions.EffectOnly);
if (SfStatus.Cancel == file.WaitForDoneOrCancel())
break;
SfAudioMarker mk = file.Markers[2];
// get the 3rd marker or region.
file.CropAudio(mk.Start, mk.Length);
}

foreach (ISfFileHost file in files)
{
// pull the filename apart, so that we can add the Track #
string strDir = Path.GetDirectoryName(strBaseFilename);
string strBase = Path.GetFileNameWithoutExtension(strBaseFilename);
string strExt = Path.GetExtension(strBaseFilename);
// build a new filename from the basic filename + the track #
string strFilename = Path.Combine(strDir, strBase + "-" + file.Summary.TrackNo + strExt);
// Save to that filename
file.SaveAs(strFilename, rend.Guid, tpl, RenderOptions.RenderOnly);
file.WaitForDoneOrCancel();
// uncomment this if you want to close the files after they have been saved.
file.Close(CloseOptions.FailIfChanged);
}

return;
}

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)); }
} //EntryPoint

Message last edited on10/30/2005 9:32:57 PM byregex_jedi.
Subject:RE: script works fine.. but crashes at end
Reply by: regex_jedi
Date:10/30/2005 9:44:13 PM

I used MessageBox dialogs to trace through the script and it gets to the "return" at the end of the Begin method. I didn't put more messageboxes in the "FromSoundForge" method to see where it crashed after the Begin(app); call. The error dialog that comes up is titled "Microsoft Visual C++ Runtime Library" (title bar). Its content says


Runtime Error!

Program: C:\Program Files\Sony\Sound Forge 8.0\Forge80.exe

This application has requested the Runtime to terminate it in a na unusual way. Please contact the application's support team for more information.

[ OK ]



that is the error dialog.

Clicking the OK button doesn't close the Sound Forge app, though, and in the bottom of the Sound Forge application window, the status window pane says "Script 'Rip and Prep Clips.cs' is done" (that is the name of the script). This tells me that FromSoundForge completed fine, and something more sinister has happened with Sound Forge.

Any clues on what I have missed here?

thanks
regex_jedi

Message last edited on11/7/2005 6:17:49 PM byregex_jedi.
Subject:RE: script works fine.. but crashes at end
Reply by: _TJ
Date:10/31/2005 9:19:53 PM

If you don't close the files does it still crash?

if it doesn't crash in that case, try emptying out the ArrayList
before you exit.

for (uint ii = 0; ii < files.Count; ++iI)
{
files[ii] = null;
}

Subject:RE: script works fine.. but crashes at end
Reply by: regex_jedi
Date:11/1/2005 12:44:41 AM

hmmm... i tried to add the loop above, but the files[ii] assignment doesn't compile (Compiler error 0x80004005 on Line 97,8 : The best overloaded method match for 'System.Collections.ArrayList.this[int]' has some invalid arguments).

regex_jedi

Subject:RE: script works fine.. but crashes at end
Reply by: regex_jedi
Date:11/1/2005 12:50:25 AM

also, you were correct about something being wrong with the files on exit.. when i DONT close them in the script .. it completes correctly and doesn't crash..

so now, I guess I just need to find out how to do proper garbage collection on that array list before exitting..

regex_jedi

Subject:RE: script works fine.. but crashes at end
Reply by: _TJ
Date:11/1/2005 11:32:11 PM

Ah yes, an ArrayList isn't exactly an array,

The proper way to remove an element is

files.Remove(file);

Or you can put

files.Clear();

after the last loop just before the script exits.

According to one of my co, workers. we can reproduce the crash, so I'll have a look at some point and see if I can't figure out what's happening. For now I think you can assume that the crash is not your fault, but I'm pretty sure that the fix is going to have something to do with emptying the ArrayList before the script exits.

tj



Message last edited on11/1/2005 11:34:19 PM by_TJ.
Subject:RE: script works fine.. but crashes at end
Reply by: regex_jedi
Date:11/2/2005 12:25:58 AM

well, I must have nerfs on my brain, cause this is still crashing for me.. the first one ("files.Remove(file);") crashes inside the last loop, the first iteration through... the second one ("files.Clear();") is placed as you suggest and it completes and exits, but still crashes after all is done, like before...

thanks for your patience in helping me through this..

regex_jedi

Message last edited on11/2/2005 12:26:43 AM byregex_jedi.
Subject:RE: script works fine.. but crashes at end
Reply by: regex_jedi
Date:11/2/2005 11:33:01 PM

I have been trying other things like REmove and RemoveAt on the ArrayList items, but nothing seems to work..

did you find any clues on how to successfully close the files and finish this script?

regex_jedi

Subject:RE: script works fine.. but crashes at end
Reply by: _TJ
Date:11/3/2005 12:16:46 AM

try using file.RenderAs(...) instead of file.SaveAs(..). I'm seeng the crash
but I don't yet understand it.

But file.SaveAs() causes us to try and re-open the file after it's saved, I think
that might be part of the problem.

If you use file.RenderAs(), then you needto use the CloseOptions.DiscardChanges flag on file.Close() or you will get an error.

tj

Subject:RE: script works fine.. but crashes at end
Reply by: regex_jedi
Date:11/3/2005 3:47:00 PM

i tried using RenderAs and the close options as suggested... :(

still crashes...

regex_jedi

Subject:RE: script works fine.. but crashes at end
Reply by: ForumAdmin
Date:11/4/2005 8:59:04 AM

To make sure we're looking at the same thing, what are the settings for your "16 bars" Auto-Region preset?

You may also want to add if (2 < file.MarkerCount) just prior to the marker assignment and crop on the off chance that the auto-region didn't create three markers (but you'd be getting a different exception if that was the problem).

J.

Message last edited on11/4/2005 11:30:36 AM byForumAdmin.
Subject:RE: script works fine.. but crashes at end
Reply by: regex_jedi
Date:11/4/2005 11:04:45 PM

the "16bars" preset is an Auto Region preset that has "Build regions using the current tempo" selected, Measures is set to 16, and Beats to 0.

That is it... btw, i added the if statement too... thanks for that..

I was thinking of trying to get the new Visual C# from Microsoft to debug this.. but I am hoping that if you have all of this you can find the problem and fix before I have to do that...

regex_jedi

Subject:RE: script works fine.. but crashes at end
Reply by: _TJ
Date:11/6/2005 1:03:17 PM

If I understand this correctly, The purpose of Auto Region is to allow you to
grab 16 bars of music from the middle of the song.

But it seems to me that since these are just ripped tracks, Sound Forge has no idea what the actual tempo of the music, so the 'tempo' of the song is just going to be 120 BMP (i.e the default value).

Which means that saving off region 4 from Auto Region is really just the equivalent of
selecting 32 seconds of music starting from 96 seconds from the start of the song. The rest of the ripped data gets thrown away - Correct?

Which means that we can speed up the script rather significantly by only ripping 32 seconds worth of music in the first place.


// Now rip each track in the Audio CD to a separate file,
// and store the file objects in an array so we can use them for processing later.
//
System.Collections.ArrayList files = new System.Collections.ArrayList();
foreach (SfAudioMarker mk in drvToRip.DiscTOC.MarkerList())
{
// rip starting at 96 seconds (in samples at 44100 samples/sec) into the song
Int64 ccStart = mk.Start + 44100*96;

// rip for 32 seconds or the length of the song (whichever is smaller)
Int64 ccLength = Math.Min(44100*32, mk.Length); // length of 32 seconds (in samples at 44100 samples/sec)

// start earlier if the rip would take us past the end of the song)
if (ccStart + ccLength > mk.Start + mk.Length)
ccStart = mk.Start + mk.Length - ccLength;

ISfFileHost file = drvToRip.ExtractAudio(mk.Name,ccStart,ccLength,0);
if (null == file)
break;
if (SfStatus.Cancel == file.WaitForDoneOrCancel())
break;
file.Summary.Title = mk.Name;
file.Summary.TrackNo = mk.Ident.ToString();
files.Add(file);
}

/* don't need to do this anymore

foreach (ISfFileHost file in files)
{
file.DoEffect("Auto Region", "16bars", SfAudioSelection.All, EffectOptions.EffectOnly);
if (SfStatus.Cancel == file.WaitForDoneOrCancel())
break;
SfAudioMarker mk = file.Markers[2];
// get the 3rd marker or region.
file.CropAudio(mk.Start, mk.Length);
}

*/


By the way. I tried your script at home and I'm not seeing the crash. Do you have a single processor or a dual processor machine? Hyperthreaded? Dual Core?

tj

Subject:RE: script works fine.. but crashes at end
Reply by: _TJ
Date:11/6/2005 1:05:03 PM

I just caught this...

Runtime Error!

Program: C:\Program Files\Sony\Sound Forge 9.0\Forge90.exe

This application has requested the Runtime to terminate it in a na unusual way. Please contact the application's support team for more information.

[ OK ]

Serously? Sound Forge 9.0? Where on earth did you get a copy of Sound Forge 9.0?

tj

Subject:RE: script works fine.. but crashes at end
Reply by: regex_jedi
Date:11/7/2005 6:20:36 PM

lol... no that was simply a typo.. the error message is in a non-copyable modal dialog box, so I had to hand type the message to this forum post pad... I simply mistyped the number on the said message.. in fact I have Version 8.0b (build 110) of sound forge...

my error still happens.. and i editted that post so it reads the proper version #..

regex_jedi

Subject:RE: script works fine.. but crashes at end
Reply by: _TJ
Date:11/8/2005 3:52:13 PM

Did you notice the post I put up before the Forge 9.0 query? I'd like to know if you are using a single processor or dual processor.

Subject:RE: script works fine.. but crashes at end
Reply by: regex_jedi
Date:11/9/2005 3:01:49 AM

i have an Dell Inspiron XPS laptop with a pentium 4/hyperthreaded extreme edition processor. 3.4Ghz speed. 2Gb of RAM. I believe it is a hyper thread appearing as two processors.

the system info is as follows- (personaly info removed)

System Information report written at: 11/09/05 03:56:27
System Name: XXXXXXXXX
[System Summary]

Item Value
OS Name Microsoft Windows XP Professional
Version 5.1.2600 Service Pack 2 Build 2600
OS Manufacturer Microsoft Corporation
System Name XXXXXXXXX
System Manufacturer Dell Inc.
System Model Inspiron XPS
System Type X86-based PC
Processor x86 Family 15 Model 2 Stepping 5 GenuineIntel ~3391 Mhz
Processor x86 Family 15 Model 2 Stepping 5 GenuineIntel ~3391 Mhz
BIOS Version/Date Dell Inc. A05, 11/1/2004
SMBIOS Version 2.3
Windows Directory C:\WINDOWS
System Directory C:\WINDOWS\system32
Boot Device \Device\HarddiskVolume2
Locale United States
Hardware Abstraction Layer Version = "5.1.2600.2180 (xpsp_sp2_rtm.040803-2158)"
User Name XXXXXXX\XXXXXXX
Time Zone US Mountain Standard Time
Total Physical Memory 2,048.00 MB
Available Physical Memory 1.37 GB
Total Virtual Memory 2.00 GB
Available Virtual Memory 1.96 GB
Page File Space 3.85 GB
Page File C:\pagefile.sys

Subject:RE: script works fine.. but crashes at end
Reply by: regex_jedi
Date:11/9/2005 3:04:26 AM

the 16 bars does not work the way you think.. Sound Forge is able to ascertain measures by reading the file and determining its measures automatically, regardless of tempo (it determines tempo).. I am wondering what function you are using wiht autoregion and measures if you can't see this done...

anyways, it works fine using auto region that way... my script though still crashes..

regex_jedi

Subject:RE: script works fine.. but crashes at end
Reply by: regex_jedi
Date:11/9/2005 3:08:34 AM

yuck.. i am sorry.. you are right.. it was not doing what i thought... weird.. well i can do this in Live (Ableton).. is there a way to read and estimate tempo in Sound Forge? lol..

even once i get what i want in the clip.. how do i get to stop the crashing?

regex_jedi

Subject:RE: script works fine.. but crashes at end
Reply by: regex_jedi
Date:11/15/2005 2:00:23 AM

so did we pretty much give up the crash though? is there any help in erradicating the cause of the crash?

regex_jedi

Subject:RE: script works fine.. but crashes at end
Reply by: _TJ
Date:11/15/2005 3:34:47 PM

Unfortunately, this is a Sound Forge bug, and there will not be an update of Sound Forge 8.0 to fix is for quite a while if at all.

The problem is that the line

SfAudioMarker mk = file.Markers[2];

creates a dangling reference to the ISfFileHost object, if that reference is released before the file is closed, everything is fine, but if it is released after, then Sound Forge will crash. The dangling reference is a bug in Sound Forge and can only be fixed by by us.

Now, since this script doesn't really need to use Auto Region or reference the markers that Auto Region creates, you can get rid of the crashing by just removing that code and replacing it with

SfAudioMarker mk = new SfAudioMarker(44100*96, 44100*32);


Or you can just not have the script close the files.

Either of these will prevent the crash.
tj



Message last edited on11/15/2005 4:35:42 PM by_TJ.

Go Back