fix for handling DnD path data, plus lots of d-n-d drop debugging (to be cleaned up)
authorPaul Davis <paul@linuxaudiosystems.com>
Sun, 9 Nov 2008 22:08:18 +0000 (22:08 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Sun, 9 Nov 2008 22:08:18 +0000 (22:08 +0000)
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@4129 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/editor.cc
gtk2_ardour/editor_audio_import.cc
gtk2_ardour/editor_canvas.cc
gtk2_ardour/editor_region_list.cc
libs/ardour/import.cc
libs/ardour/sndfileimportable.cc
libs/gtkmm2ext/gtkmm2ext/dndtreeview.h

index 49aa9010f51e5f809d2eda97491773cddc0d2cbe..e4514dd8795698816596e38337b52db00e418de6 100644 (file)
@@ -3048,12 +3048,19 @@ Editor::convert_drop_to_paths (vector<ustring>& paths,
                }
   
                /* Parse the "uri-list" format that Nautilus provides, 
-                  where each pathname is delimited by \r\n
+                  where each pathname is delimited by \r\n.
+
+                  THERE MAY BE NO NULL TERMINATING CHAR!!!
                */
-       
-               const char* p = data.get_text().c_str();
+
+               ustring txt = data.get_text();
+               const char* p;
                const char* q;
 
+               p = (const char *) malloc (txt.length() + 1);
+               txt.copy ((char *) p, txt.length(), 0);
+               ((char*)p)[txt.length()] = '\0';
+
                while (p)
                {
                        if (*p != '#')
@@ -3062,8 +3069,9 @@ Editor::convert_drop_to_paths (vector<ustring>& paths,
                                        p++;
                                
                                q = p;
-                               while (*q && (*q != '\n') && (*q != '\r'))
+                               while (*q && (*q != '\n') && (*q != '\r')) {
                                        q++;
+                               }
                                
                                if (q > p)
                                {
@@ -3082,6 +3090,8 @@ Editor::convert_drop_to_paths (vector<ustring>& paths,
                                p++;
                }
 
+               free ((void*)p);
+               
                if (uris.empty()) {
                        return -1;
                }
index b290a54f4cfd21e7059099d3c0ed91a9b0aff39f..d8be18300ffe6636a17a89a1d9c436942bbcfa04 100644 (file)
@@ -310,6 +310,8 @@ Editor::_do_import (vector<ustring> paths, ImportDisposition chns, ImportMode mo
                build_interthread_progress_window ();
        }
 
+       cerr << "Here we go .. disp = " << chns << " mode = " << mode << " @ " << pos << endl;
+
        if (chns == Editing::ImportMergeFiles) {
                /* create 1 region from all paths, add to 1 track,
                   ignore "track"
@@ -324,6 +326,7 @@ Editor::_do_import (vector<ustring> paths, ImportDisposition chns, ImportMode mo
                }
 
                if (!cancel) {
+                       cerr << "Here we REALLY go ..\n";
                        if (import_sndfiles (paths, mode, quality, pos, 1, 1, track, false)) {
                                ok = false;
                        }
@@ -362,6 +365,7 @@ Editor::_do_import (vector<ustring> paths, ImportDisposition chns, ImportMode mo
                                                track = get_nth_selected_audio_track (nth++);
                                        }
 
+                                       cerr << "Here we REALLY go 2 ..\n";
                                        if (import_sndfiles (to_import, mode, quality, pos, 1, -1, track, replace)) {
                                                ok = false;
                                        }
@@ -373,6 +377,7 @@ Editor::_do_import (vector<ustring> paths, ImportDisposition chns, ImportMode mo
                                        to_import.clear ();
                                        to_import.push_back (*a);
 
+                                       cerr << "Here we REALLY go 3 ..\n";
                                        if (import_sndfiles (to_import, mode, quality, pos, -1, -1, track, replace)) {
                                                ok = false;
                                        }
@@ -388,6 +393,7 @@ Editor::_do_import (vector<ustring> paths, ImportDisposition chns, ImportMode mo
                                           reuse "track" across paths
                                           */
 
+                                       cerr << "Here we REALLY go 4 ..\n";
                                        if (import_sndfiles (to_import, mode, quality, pos, 1, 1, track, replace)) {
                                                ok = false;
                                        }
@@ -501,7 +507,7 @@ Editor::import_sndfiles (vector<ustring> paths, ImportMode mode, SrcQuality qual
        interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
        interthread_progress_bar.set_fraction (0.0f);
        interthread_cancel_label.set_text (_("Cancel Import"));
-       current_interthread_info = &import_status;
+       current_interthread_info = &import_status;
 
        import_status.paths = paths;
        import_status.done = false;
@@ -521,13 +527,20 @@ Editor::import_sndfiles (vector<ustring> paths, ImportMode mode, SrcQuality qual
           and if successful will add the file(s) as a region to the session region list.
        */
        
+       cerr << "Creating import thread\n";
+
        pthread_create_and_store ("import", &import_status.thread, 0, _import_thread, this);
        pthread_detach (import_status.thread);
        
+       cerr << "into rec loop while thread runs\n";
+
        while (!(import_status.done || import_status.cancel)) {
                gtk_main_iteration ();
        }
 
+       cerr << "back from rec loop while thread run, status.cancel = " << import_status.cancel
+            << " done = " << import_status.done << " progress = " << import_status.progress << endl;
+
        interthread_progress_window->hide ();
        
        import_status.done = true;
@@ -538,6 +551,7 @@ Editor::import_sndfiles (vector<ustring> paths, ImportMode mode, SrcQuality qual
        boost::shared_ptr<AudioRegion> r;
        
        if (import_status.cancel || import_status.sources.empty()) {
+               cerr << "Cancelled ? " << import_status.cancel << " or no files\n";
                goto out;
        }
 
index 7aed0670106123380d93a62cfafc7d9fbe2ba306..fbfd4770e796be2b78bf8e81d6f64d6e3c81b4e6 100644 (file)
@@ -474,6 +474,10 @@ Editor::drop_paths (const RefPtr<Gdk::DragContext>& context,
                goto out;
        }
 
+       for (vector<ustring>::iterator xx = paths.begin(); xx != paths.end(); ++xx) {
+               cerr << "Drop path = " << *xx << endl;
+       }
+
        /* D-n-D coordinates are window-relative, so convert to "world" coordinates
         */
 
index 666fadb790f1e5a8b3c71545008e26188b8121e5..b3bfbcc95f13808d3038cce0f6581ae84a3c654c 100644 (file)
@@ -386,8 +386,6 @@ Editor::region_list_display_button_press (GdkEventButton *ev)
        int cellx;
        int celly;
 
-       // cerr << "Button press release, button = " << ev->button << endl;
-
        if (region_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
                if ((iter = region_list_model->get_iter (path))) {
                        region = (*iter)[region_list_columns.region];
@@ -396,12 +394,10 @@ Editor::region_list_display_button_press (GdkEventButton *ev)
 
        if (Keyboard::is_context_menu_event (ev)) {
                show_region_list_display_context_menu (ev->button, ev->time);
-               cerr << "\tcontext menu event, event handled\n";
                return true;
        }
 
        if (region == 0) {
-               cerr << "\tno region, event not handled\n";
                return false;
        }
 
@@ -414,7 +410,6 @@ Editor::region_list_display_button_press (GdkEventButton *ev)
                if (!Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
                        consider_auditioning (region);
                }
-               cerr << "\taudition, event handled\n";
                return true;
                break;
 
@@ -422,7 +417,6 @@ Editor::region_list_display_button_press (GdkEventButton *ev)
                break; 
        }
 
-       cerr << "\tnot handled\n";
        return false;
 }      
 
index 2694acd9ab50a13aeab292dc66a72e6707b4538f..9f103346fd900b67312e5b947c00fc2fb9c4fac9 100644 (file)
@@ -87,10 +87,12 @@ open_importable_source (const string& path, nframes_t samplerate, ARDOUR::SrcQua
                try { 
                        boost::shared_ptr<SndFileImportableSource> source(new SndFileImportableSource(path));
                        
+                       cerr << "Got a new sndfile source from " << path << " as " << source->length() << endl;
+
                        if (source->samplerate() == samplerate) {
                                return source;
                        }
-
+                       
                        /* rewrap as a resampled source */
                        
                        return boost::shared_ptr<ImportableSource>(new ResampledImportableSource(source, samplerate, quality));
@@ -244,6 +246,8 @@ write_audio_data_to_new_files (ImportableSource* source, Session::import_status&
        boost::scoped_array<float> data(new float[nframes * channels]);
        vector<boost::shared_array<Sample> > channel_data;
 
+       cerr << "writing " << channels << " to new file, length = " << source->length() << endl;
+
        for (uint n = 0; n < channels; ++n) {
                channel_data.push_back(boost::shared_array<Sample>(new Sample[nframes]));
        }
@@ -280,6 +284,8 @@ write_audio_data_to_new_files (ImportableSource* source, Session::import_status&
 
                read_count += nread;
                status.progress = read_count / (source->ratio () * source->length() * channels);
+
+               cerr << "status.progress = " << status.progress << endl;
        }
 }
 
@@ -300,6 +306,9 @@ Session::import_audiofiles (import_status& status)
        typedef vector<boost::shared_ptr<AudioFileSource> > AudioSources;
        AudioSources all_new_sources;
 
+
+       cerr << "start import of AF\n";
+
        status.sources.clear ();
        
        for (vector<Glib::ustring>::iterator p = status.paths.begin();
@@ -311,11 +320,13 @@ Session::import_audiofiles (import_status& status)
                try
                {
                        source = open_importable_source (*p, frame_rate(), status.quality);
+                       cerr << "New source from " << *p << " length = " << source->length() << endl;
                }
                
                catch (const failed_constructor& err)
                {
                        error << string_compose(_("Import: cannot open input sound file \"%1\""), (*p)) << endmsg;
+                       cerr << string_compose(_("Import: cannot open input sound file \"%1\""), (*p)) << endl;
                        status.done = status.cancel = true;
                        return;
                }
@@ -346,6 +357,8 @@ Session::import_audiofiles (import_status& status)
                status.doing_what = compose_status_message (*p, source->samplerate(),
                                frame_rate(), cnt, status.paths.size());
 
+               cerr << "about to write audio data\n";
+               
                write_audio_data_to_new_files (source.get(), status, newfiles);
        }
 
@@ -374,13 +387,13 @@ Session::import_audiofiles (import_status& status)
 
                save_state (_name);
 
-               std::copy (all_new_sources.begin(), all_new_sources.end(),
-                               std::back_inserter(status.sources));
+               std::copy (all_new_sources.begin(), all_new_sources.end(), std::back_inserter(status.sources));
        } else {
                // this can throw...but it seems very unlikely
                std::for_each (all_new_sources.begin(), all_new_sources.end(), remove_file_source);
        }
 
+       cerr << "end of import, setting done = true\n";
        status.done = true;
 }
 
index eb0e8a8afbcde6345b6f777ebc215f17af9db6ef..542999f6f119224b06a3ada7f641840b8e6815f4 100644 (file)
@@ -1,5 +1,6 @@
 #include <ardour/sndfileimportable.h>
 #include <sndfile.h>
+#include <iostream>
 
 using namespace ARDOUR;
 using namespace std;
@@ -8,6 +9,7 @@ SndFileImportableSource::SndFileImportableSource (const string& path)
        : in (sf_open (path.c_str(), SFM_READ, &sf_info), sf_close)
 {
        if (!in) throw failed_constructor();
+       std::cerr << "new SFIS @ " << path << " frames = " << sf_info.frames << std::endl;
 }
 
 SndFileImportableSource::~SndFileImportableSource ()
index 7b2c8d9882c7bebf78307efa71e4a87ae71eadb6..92872ee60fd393b7d149f67351d2b0bc652faeb6 100644 (file)
@@ -74,6 +74,7 @@ class DnDTreeView : public DnDTreeViewBase
        sigc::signal<void,std::string,uint32_t,const DataType*> signal_object_drop;
 
        void on_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, Gtk::SelectionData& selection_data, guint info, guint time) {
+               std::cerr << "DRAG DATA Get, context = " << context->gobj() << " src = " << context->gobj()->is_source << std::endl;
                if (selection_data.get_target() == "GTK_TREE_MODEL_ROW") {
                        
                        TreeView::on_drag_data_get (context, selection_data, info, time);
@@ -85,8 +86,9 @@ class DnDTreeView : public DnDTreeViewBase
                        selection_data.set (8, (guchar*)sr, sr->size);
                }
        }
-
+       
        void on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& selection_data, guint info, guint time) {
+               std::cerr << "DRAG DATA Receive, context = " << context->gobj() << " src = " << context->gobj()->is_source << std::endl;
                if (suggested_action) {
                        /* this is a drag motion callback. just update the status to
                           say that we are still dragging, and that's it.