How to add label List to project?

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:

AudacityProject* pProject = GetActiveProject();
pProject->OnRecord();

And sorry for my skills in english =)

Does this help?
http://manual.audacityteam.org/o/man/importing_and_exporting_labels.html

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:

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).

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.

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

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

It’s still in SVN (in “/lib-src”).

I see, however, it is no longer linked to the Windows project.

There are couple of places in the code where label tracks are created:

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:

void AudacityProject::OnImportLabels()
{
   […]
      LabelTrack *newTrack = new LabelTrack(mDirManager);

mDirManager is a member of a AudacityProject:

class AUDACITY_DLL_API AudacityProject:  […]
{
 […]
   DirManager *mDirManager;

so using your project variable:

 
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).

And my final code is

		
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.

Just FYI, One of the Audacity Developers has written a comment in the code that

GetActiveProject();

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:

      
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]