Update of /cvsroot/audacity/audacity-src/src
In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv13820

Modified Files:
        AudacityApp.cpp AudacityApp.h Project.cpp Project.h 
Log Message:
Rework of DDE processing on Windows to work without having to update existing 
registry keys and to better handle many instances starting up at once.

Index: Project.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/Project.h,v
retrieving revision 1.114
retrieving revision 1.115
diff -u -d -r1.114 -r1.115
--- Project.h   19 Feb 2007 06:25:51 -0000      1.114
+++ Project.h   11 Apr 2007 06:07:18 -0000      1.115
@@ -201,6 +201,7 @@
    void OnCloseWindow(wxCloseEvent & event);
    void OnTimer(wxTimerEvent & event);
    void OnToolBarUpdate(wxCommandEvent & event);
+   void OnOpenAudioFile(wxCommandEvent & event);
    void OnCaptureKeyboard(wxCommandEvent & event);
    void OnReleaseKeyboard(wxCommandEvent & event);
    bool HandleKeyDown(wxKeyEvent & event);

Index: Project.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/Project.cpp,v
retrieving revision 1.301
retrieving revision 1.302
diff -u -d -r1.301 -r1.302
--- Project.cpp 10 Apr 2007 02:21:45 -0000      1.301
+++ Project.cpp 11 Apr 2007 06:07:18 -0000      1.302
@@ -435,6 +435,7 @@
     // Update menu method
     EVT_UPDATE_UI(1, AudacityProject::OnUpdateMenus)
     EVT_ICONIZE(AudacityProject::OnIconize)
+    EVT_COMMAND(wxID_ANY, EVT_OPEN_AUDIO_FILE, 
AudacityProject::OnOpenAudioFile)
     EVT_COMMAND(wxID_ANY, EVT_TOOLBAR_UPDATED, 
AudacityProject::OnToolBarUpdate)
     EVT_COMMAND(wxID_ANY, EVT_CAPTURE_KEYBOARD, 
AudacityProject::OnCaptureKeyboard)
     EVT_COMMAND(wxID_ANY, EVT_RELEASE_KEYBOARD, 
AudacityProject::OnReleaseKeyboard)
@@ -1504,6 +1505,17 @@
    Destroy();
 }
 
+void AudacityProject::OnOpenAudioFile(wxCommandEvent & event)
+{
+   wxString cmd = event.GetString();
+
+   if (!cmd.IsEmpty()) {
+      OpenFile(cmd);
+   }
+
+   RequestUserAttention();
+}
+
 void AudacityProject::OnCaptureKeyboard(wxCommandEvent & event)
 {
    CaptureKeyboard((wxWindow *)event.GetEventObject());

Index: AudacityApp.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/AudacityApp.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- AudacityApp.h       10 Apr 2007 03:57:47 -0000      1.33
+++ AudacityApp.h       11 Apr 2007 06:07:18 -0000      1.34
@@ -29,6 +29,9 @@
 
 extern bool gIsQuitting;
 
+// Asynchronous open
+DECLARE_EVENT_TYPE(EVT_OPEN_AUDIO_FILE, -1);
+
 // Keyboard capture support
 DECLARE_EVENT_TYPE(EVT_CAPTURE_KEYBOARD, -1);
 DECLARE_EVENT_TYPE(EVT_RELEASE_KEYBOARD, -1);

Index: AudacityApp.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/AudacityApp.cpp,v
retrieving revision 1.167
retrieving revision 1.168
diff -u -d -r1.167 -r1.168
--- AudacityApp.cpp     10 Apr 2007 04:05:26 -0000      1.167
+++ AudacityApp.cpp     11 Apr 2007 06:07:18 -0000      1.168
@@ -150,6 +150,7 @@
 /// Custom events
 ////////////////////////////////////////////////////////////
 
+DEFINE_EVENT_TYPE(EVT_OPEN_AUDIO_FILE);
 DEFINE_EVENT_TYPE(EVT_CAPTURE_KEYBOARD);
 DEFINE_EVENT_TYPE(EVT_RELEASE_KEYBOARD);
 DEFINE_EVENT_TYPE(EVT_CAPTURE_KEY);
@@ -248,6 +249,11 @@
 
 #if defined(__WXMSW__)
 
+//
+// DDE support for opening multiple files with one instance
+// of Audacity.
+//
+
 #define IPC_APPL wxT("audacity")
 #define IPC_TOPIC wxT("System")
 
@@ -272,11 +278,19 @@
          return false;
       }
 
-      AudacityProject *project = GetActiveProject();
-      if (project == NULL || !project->GetTracks()->IsEmpty()) {
-         project = CreateNewAudacityProject(gParentWindow);
+      AudacityProject *project = CreateNewAudacityProject(gParentWindow);
+
+      wxString cmd(data);
+
+      // We queue a command event to the project responsible for 
+      // opening the file since it can be a long process and we
+      // only have 5 seconds to return the Execute message to the
+      // client.
+      if (!cmd.IsEmpty()) {
+         wxCommandEvent e(EVT_OPEN_AUDIO_FILE);
+         e.SetString(data);
+         project->AddPendingEvent(e);
       }
-      project->OpenFile(wxString(data));
 
       return true;
    };
@@ -862,10 +876,6 @@
 
 #endif // Cygwin command-line parser
 
-#if defined(__WXMSW__)
-   mIPCServ = new IPCServ();
-#endif
-
    gInited = true;
    
    return TRUE;
@@ -1019,6 +1029,32 @@
       }
    }
    else if ( mChecker->IsAnotherRunning() ) {
+#if defined(__WXMSW__)
+      //
+      // On Windows (and possibly Linux?), we attempt to make
+      // a DDE connection to an already active Audacity.  If
+      // successful, we send the first command line argument
+      // (the audio file name) to that Audacity for processing.
+      wxClient client;
+      wxConnectionBase *conn;
+
+      // We try up to 10 times since there's a small window
+      // where the DDE server may not have been fully initialized
+      // yet.
+      for (int i = 0; i < 10; i++) {
+         conn = client.MakeConnection(wxEmptyString,
+                                      IPC_APPL,
+                                      IPC_TOPIC);
+         if (conn) {
+            if (conn->Execute(argv[1])) {
+               // Command was successfully queued so exit quietly
+               delete mChecker;
+               return false;
+            }
+         }
+         wxMilliSleep(100);
+      }
+#endif
       // There is another copy of Audacity running.  Force quit.
       
       wxString prompt =
@@ -1031,6 +1067,11 @@
       return false;
    }
 
+#if defined(__WXMSW__)
+   // Create the DDE server
+   mIPCServ = new IPCServ();
+#endif
+
    return true;
 }
 
@@ -1348,9 +1389,13 @@
                if (!associateFileTypes.Exists() || 
                      (tmpRegAudPath.Find(wxT("audacity.exe")) >= 0)) {
                   associateFileTypes.Create(true);
-                  associateFileTypes = (wxString)argv[0]; // + (wxString)wxT(" 
\"%1\"");
+                  associateFileTypes = (wxString)argv[0] + (wxString)wxT(" 
\"%1\"");
                }
 
+#if 0
+               // These can be use later to support more startup messages
+               // like maybe "Import into existing project" or some such.
+               // Leaving here for an example...
                associateFileTypes.SetName(root_key + 
wxT("Audacity.Project\\shell\\open\\ddeexec"));
                if(!associateFileTypes.Exists()) {
                   associateFileTypes.Create(true);
@@ -1368,6 +1413,7 @@
                   associateFileTypes.Create(true);
                   associateFileTypes = IPC_TOPIC;
                }
+#endif
             }
          } else {
             // User said no. Set a pref so we don't keep asking.


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Audacity-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to