Community Forums Archive

Go Back

Subject:Writing Markers To ID3 Comment Tag
Posted by: dreid
Date:12/13/2006 9:27:38 PM

I recently came across a nice little script:
http://www.herrodius.com/blog/?p=49

that will read markers in sound forge and dump the timecodes into the "Comment" tag of the mp3 file. the idea is great for using cue points within a flash movie, as flash can read the id3 tag and you don't need any external files.

problem is though, that it seems to get cut off at the 29th character with both id3v1 and id3v2 selected and i can't quite figure out why. is this just a limitation of the file type? I've tried putting in dummy data that is longer than 29 characters and it won't fill either.

thanks for reading this far...

Dunc

Message last edited on12/13/2006 9:58:02 PM bydreid.
Subject:RE: Writing Markers To ID3 Comment Tag
Reply by: _TJ
Date:12/13/2006 10:08:54 PM

That is a clever little script.
Thanks for giving us a pointer to it.

Here's on that dumps markers for all open files into a text file.
I think I may have shared this one before....

------------ DumpRegionsToFile.cs --------------

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

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

int cFilesWithMarkers = 0;

string sLogFile = PromptForLogFile(@"e:\Media\Streaming Files\regionlist.txt");
if (null == sLogFile)
return "no output filename";

FileInfo fi = new FileInfo(sLogFile);
StreamWriter stm = fi.AppendText();

foreach (ISfFileHost file in app.Files)
{
if (file.MarkerCount > 0)
{
WriteMarkersToStream(stm, file);
cFilesWithMarkers++;
}
else
{
DPF("'{0}' does not contain any markers.", file.Filename);
}
}
stm.Close();

DPF("{0} file(s) affected", cFilesWithMarkers);
return String.Format("{0} file(s) affected. Script {1} is done.", cFilesWithMarkers, Script.Name);
}

public void WriteMarkersToStream(StreamWriter stm, ISfFileHost file)
{
stm.WriteLine(String.Format("\"{0}\", {1} markers and regions", file.Filename, file.MarkerCount));

ISfPositionFormatter PosFmt = file.Formatter;

int ii = 0;
foreach (SfAudioMarker mk in file.Markers)
{
string str;
if (mk.HasLength)
str = String.Format("{0:d3} {2}, {3}, \"{1}\"", mk.Ident, mk.Name, PosFmt.Format(mk.Start), PosFmt.Format(mk.Length));
else
str = String.Format("{0:d3} {2}, , \"{1}\"", mk.Ident, mk.Name, PosFmt.Format(mk.Start));

stm.WriteLine(str);
++ii;
}

stm.WriteLine("");
stm.Flush();
}

public string PromptForLogFile(string sDefault)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "Choose output file.";
sfd.FileName = sDefault;
sfd.Filter = "Text (*.txt)|*.txt";
sfd.DefaultExt = "txt";
if (DialogResult.OK != sfd.ShowDialog())
return null;

return sfd.FileName;
}

public void FromSoundForge(IScriptableApp app) {
ForgeApp = app; //execution begins here
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));
}
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)); }
public static string GETARG(string k, string d) { string val = Script.Args.ValueOf(k); if (val == null || val.Length == 0) val = d; return val; }
public static int GETARG(string k, int d) { string s = Script.Args.ValueOf(k); if (s == null || s.Length == 0) return d; else return Script.Args.AsInt(k); }
public static bool GETARG(string k, bool d) { string s = Script.Args.ValueOf(k); if (s == null || s.Length == 0) return d; else return Script.Args.AsBool(k); }
} //EntryPoint



Subject:RE: Writing Markers To ID3 Comment Tag
Reply by: dreid
Date:12/14/2006 6:30:14 AM

thanks TJ, your right, i found that script not too long after posting...

is there a way to sort the markers w/o pushing them all into an array and sorting that?

in the event there might be a marker added at a later date it seems to come up on the end of the list.


* edit *
I'm not much of a C# guy, is Visual Studio Express a descent editor? I'd like something that provides hinting.

Message last edited on12/14/2006 6:45:12 AM bydreid.
Subject:RE: Writing Markers To ID3 Comment Tag
Reply by: _TJ
Date:12/14/2006 1:55:19 PM

is there a way to sort the markers w/o pushing them all into an array and sorting that?

No, copying the markers into an array and then sorting the array is the easiest way.

I use Visual Studio Professional, and it does a great job of hinting for coding with C#.
I have no experience with the Express version, but I imagine that it would support hinting as well.

tj

Subject:RE: Writing Markers To ID3 Comment Tag
Reply by: dreid
Date:12/15/2006 9:07:39 AM

thanks TJ, appreciate it...

Dunc

Go Back