Page 1 of 1
How to add label List to project?
Posted: Thu Aug 14, 2014 4:37 pm
by Rinin
I'm currently trying to add some features for audacity. Generally I need to comunicate with another programm and record some sound. It would be nice to add label track and some labels. And I'll be pleased if someone point me out to needed functions. Now I got own wxTimer handler in application and using:
Code: Select all
AudacityProject* pProject = GetActiveProject();
pProject->OnRecord();
And sorry for my skills in english =)
Re: How to add label List to project?
Posted: Thu Aug 14, 2014 5:03 pm
by steve
Re: How to add label List to project?
Posted: Thu Aug 14, 2014 11:24 pm
by Edgar
I think I understand that you want to have your "another program" create a list of labels (consisting of a string and an insertion point for each label) then have that program communicate with Audacity so that Audacity can actually create a label track (if needed) and add all of these labels at the appropriate insertion point in time.
If that is the case then you will need to come up with a method for the two programs to communicate. There have been some experimental attempts at this in the past; one of those (no longer included in the mainstream Audacity source code) is mod-script-pipe (It was removed sometime after SVN revision 11364).
After you figure out a way to get the two programs to communicate changing Audacity to do what you want should be fairly easy. Take a look at
int LabelTrack::AddLabel(double t, double t1, const wxString &title) at or near line number 2514 in file srcLabelTrack.cpp:
Code: Select all
int LabelTrack::AddLabel(double t, double t1, const wxString &title)
{
LabelStruct *l = new LabelStruct();
l->t = t;
l->t1 = t1;
l->title = title;
mCurrentCursorPos = title.length();
mInitialCursorPos = mCurrentCursorPos;
int len = mLabels.Count();
int pos = 0;
while (pos < len && mLabels[pos]->t < t)
pos++;
mLabels.Insert(l, pos);
mSelIndex = pos;
mDrawCursor = true;
return pos;
}
(I removed the long comment for brevity).
Re: How to add label List to project?
Posted: Fri Aug 15, 2014 12:14 am
by Rinin
Edgar wrote:I think I understand that you want to have your "another program" create a list of labels (consisting of a string and an insertion point for each label) then have that program communicate with Audacity so that Audacity can actually create a label track (if needed) and add all of these labels at the appropriate insertion point in time.
It's not exactly what I need, but close. Another programm (lets call it Alice) comunicate with audacity and sending a signal to start record. After that Alice keep checking hardware system state and generate labels on the fly. Somthing like "In this point super strong EMP generating equipment was turned on, recorded signal should be corrupted" Thats why I also need to get cureent timestamp somehow.
Edgar wrote:If that is the case then you will need to come up with a method for the two programs to communicate. There have been some experimental attempts at this in the past; one of those (no longer included in the mainstream Audacity source code) is mod-script-pipe (It was removed sometime after SVN revision 11364).
Communication shouldn't be a problem because it's limited and independent from audacity at all. So it'll be only my own code, and main problem for me is "reading" big new project like audacity
Edgar wrote:After you figure out a way to get the two programs to communicate changing Audacity to do what you want should be fairly easy. Take a look at int LabelTrack::AddLabel(double t, double t1, const wxString &title) at or near line number 2514 in file srcLabelTrack.cpp:
Thanks for pointing this out, as I understand I need firstly add
LabelTrack to
AudacityProject and then call
AddLabe for this
LabelTrack instance, calling function - not a problem, creating
LabelTrack instance also shouldn't be a problem, but I still can't found how to "connect" this new
LabelTrack to
AudacityProject
Re: How to add label List to project?
Posted: Fri Aug 15, 2014 12:59 am
by steve
Edgar wrote:There have been some experimental attempts at this in the past; one of those (no longer included in the mainstream Audacity source code) is mod-script-pipe (It was removed sometime after SVN revision 11364).
It's still in SVN (in "/lib-src").
Re: How to add label List to project?
Posted: Fri Aug 15, 2014 3:56 am
by Edgar
steve wrote:Edgar wrote:There have been some experimental attempts at this in the past; one of those (no longer included in the mainstream Audacity source code) is mod-script-pipe (It was removed sometime after SVN revision 11364).
It's still in SVN (in "/lib-src").
I see, however, it is no longer linked to the Windows project.
Re: How to add label List to project?
Posted: Fri Aug 15, 2014 4:12 am
by Edgar
Rinin wrote: I still can't found how to "connect" this new LabelTrack to AudacityProject
There are couple of places in the code where label tracks are created:
Code: Select all
Find all "LabelTrack(", Whole word, Subfolders, Find Results 2, "Entire Solution", "*.cpp"
D:AudacitySVNsrcLabelDialog.cpp(317): LabelTrack *newTrack = new LabelTrack(mDirManager);
D:AudacitySVNsrcLabelDialog.cpp(539): LabelTrack *lt = new LabelTrack(mDirManager);
D:AudacitySVNsrcLabelDialog.cpp(609): LabelTrack *lt = new LabelTrack(mDirManager);
D:AudacitySVNsrcLabelTrack.cpp(83): return new LabelTrack(mDirManager);
D:AudacitySVNsrcLabelTrack.cpp(2295): *dest = new LabelTrack(GetDirManager());
D:AudacitySVNsrcMenus.cpp(3686): t = new LabelTrack(mDirManager);
D:AudacitySVNsrcMenus.cpp(4682): LabelTrack *newTrack = new LabelTrack(mDirManager);
D:AudacitySVNsrcMenus.cpp(5457): LabelTrack *t = new LabelTrack(mDirManager);
D:AudacitySVNsrcMenus.cpp(5552): lt = new LabelTrack(mDirManager);
Matching lines: 12 Matching files: 3 Total files searched: 348
I think that the ones in Menus.cpp might be the most interesting for you to look at especially the one at line 4656:
Code: Select all
void AudacityProject::OnImportLabels()
{
[…]
LabelTrack *newTrack = new LabelTrack(mDirManager);
mDirManager is a member of a AudacityProject:
Code: Select all
class AUDACITY_DLL_API AudacityProject: […]
{
[…]
DirManager *mDirManager;
so using your project variable:
Code: Select all
LabelTrack *newTrack = new LabelTrack(pProject->mDirManager);
Re: How to add label List to project?
Posted: Fri Aug 15, 2014 10:28 am
by Rinin
Edgar wrote:Code: Select all
LabelTrack *newTrack = new LabelTrack(pProject->mDirManager);
Edgar, thanks a lot for this example, it's exactly what I need. I'll be pleased if you could help me with obtaining of current time of record, but it's not a big problem anyway, since I could count time in another programm (Alice).
Re: How to add label List to project?
Posted: Fri Aug 15, 2014 11:04 am
by Rinin
And my final code is
Code: Select all
AudacityProject* pProject;
LabelTrack* Labels_track;
TrackList* All_Tracks;
pProject = GetActiveProject();
Labels_track = new LabelTrack(pProject->GetDirManager());
Labels_track->AddLabel(0,15,L"Hello world");
All_Tracks = pProject->GetTracks();
All_Tracks->Add(Labels_track);
I hope it could help someone.
Re: How to add label List to project?
Posted: Fri Aug 15, 2014 4:34 pm
by Edgar
Just FYI, One of the Audacity Developers has written a comment in the code that
might not be 100% reliable and might return NULL even when a project exists (sorry, I don't have time to search for the specific citation). GetActiveProject is used all throughout the Audacity source code and, to the best of my knowledge, no other developer has experienced a problem with it. Nevertheless, if this is mission-critical code it might be a smart idea to wrap it in a test for a NULL return value:
Code: Select all
AudacityProject* pProject;
LabelTrack* Labels_track;
TrackList* All_Tracks;
pProject = GetActiveProject();
if (pProject) {
Labels_track = new LabelTrack(pProject->GetDirManager());
Labels_track->AddLabel(0,15,L"Hello world");
All_Tracks = pProject->GetTracks();
All_Tracks->Add(Labels_track);
}
else [SOMETHING BAD HAPPENED – fail gracefully]