13
0

Separate interthread progress window out into its own class and HIG-ify it a bit. Make the import progress bar report on the whole import rather than individual files.

git-svn-id: svn://localhost/ardour2/branches/3.0@6894 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Carl Hetherington 2010-04-14 22:16:46 +00:00
parent 8783fc35f2
commit 3d3e889dd6
8 changed files with 174 additions and 130 deletions

View File

@ -304,7 +304,6 @@ Editor::Editor ()
last_autoscroll_y = 0;
autoscroll_active = false;
autoscroll_timeout_tag = -1;
interthread_progress_window = 0;
logo_item = 0;
analysis_window = 0;

View File

@ -1174,17 +1174,6 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
boost::shared_ptr<ARDOUR::AudioTrack> get_nth_selected_audio_track (int nth) const;
boost::shared_ptr<ARDOUR::MidiTrack> get_nth_selected_midi_track (int nth) const;
/* generic interthread progress window */
ArdourDialog* interthread_progress_window;
Gtk::Label interthread_progress_label;
Gtk::VBox interthread_progress_vbox;
Gtk::ProgressBar interthread_progress_bar;
Gtk::Button interthread_cancel_button;
Gtk::Label interthread_cancel_label;
sigc::connection interthread_progress_connection;
void interthread_cancel_clicked ();
void build_interthread_progress_window ();
ARDOUR::InterThreadInfo* current_interthread_info;
AnalysisWindow* analysis_window;
@ -1201,7 +1190,6 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
};
EditorImportStatus import_status;
gint import_progress_timeout (void *);
static void *_import_thread (void *);
void* import_thread ();
void finish_import ();
@ -1795,7 +1783,6 @@ public:
/* freeze operations */
ARDOUR::InterThreadInfo freeze_status;
gint freeze_progress_timeout (void *);
static void* _freeze_thread (void*);
void* freeze_thread ();

View File

@ -58,6 +58,7 @@
#include "session_import_dialog.h"
#include "utils.h"
#include "gui_thread.h"
#include "interthread_progress_window.h"
#include "i18n.h"
@ -330,15 +331,7 @@ Editor::do_import (vector<ustring> paths, ImportDisposition chns, ImportMode mod
import_status.current = 1;
import_status.total = paths.size ();
if (interthread_progress_window == 0) {
build_interthread_progress_window ();
}
interthread_progress_window->set_title (_("Import"));
interthread_progress_bar.set_fraction (0.0f);
interthread_cancel_label.set_text (_("Cancel Import"));
interthread_progress_connection = Glib::signal_timeout().connect
(sigc::bind (sigc::mem_fun(*this, &Editor::import_progress_timeout), (gpointer) 0), 500);
ImportProgressWindow ipw (&import_status, _("Import"), _("Cancel Import"));
if (chns == Editing::ImportMergeFiles) {
@ -419,9 +412,6 @@ Editor::do_import (vector<ustring> paths, ImportDisposition chns, ImportMode mod
}
}
}
interthread_progress_window->hide_all ();
interthread_progress_connection.disconnect ();
}
void
@ -937,43 +927,3 @@ Editor::import_thread ()
/*NOTREACHED*/
return 0;
}
gint
Editor::import_progress_timeout (void */*arg*/)
{
bool reset = false;
if (!interthread_progress_window->is_visible()) {
interthread_progress_window->show_all ();
reset = true;
}
interthread_progress_label.set_markup (import_status.doing_what);
if (import_status.freeze) {
interthread_cancel_button.set_sensitive(false);
} else {
interthread_cancel_button.set_sensitive(true);
}
if (import_status.doing_what == "building peak files") {
interthread_progress_bar.pulse ();
return FALSE;
} else {
float val = import_status.progress;
interthread_progress_bar.set_fraction (min (max (0.0f, val), 1.0f));
}
if (reset) {
/* the window is now visible, speed up the updates */
interthread_progress_connection.disconnect ();
interthread_progress_connection = Glib::signal_timeout().connect
(sigc::bind (sigc::mem_fun(*this, &Editor::import_progress_timeout), (gpointer) 0), 100);
return false;
} else {
return !(import_status.done || import_status.cancel);
}
}

View File

@ -79,6 +79,7 @@
#include "editor_routes.h"
#include "editor_regions.h"
#include "quantize_dialog.h"
#include "interthread_progress_window.h"
#include "i18n.h"
@ -2602,40 +2603,6 @@ Editor::audition_playlist_region_standalone (boost::shared_ptr<Region> region)
_session->audition_region (region);
}
void
Editor::build_interthread_progress_window ()
{
interthread_progress_window = new ArdourDialog (X_("interthread progress"), true);
interthread_progress_bar.set_orientation (Gtk::PROGRESS_LEFT_TO_RIGHT);
interthread_progress_window->set_border_width (12);
interthread_progress_window->get_vbox()->set_spacing (6);
interthread_progress_label.set_alignment (0, 0.5);
interthread_progress_label.set_use_markup (true);
interthread_progress_window->get_vbox()->pack_start (interthread_progress_label, false, false);
interthread_progress_window->get_vbox()->pack_start (interthread_progress_bar,false, false);
// GTK2FIX: this button needs a modifiable label
Button* b = interthread_progress_window->add_button (Stock::CANCEL, RESPONSE_CANCEL);
b->signal_clicked().connect (sigc::mem_fun(*this, &Editor::interthread_cancel_clicked));
interthread_cancel_button.add (interthread_cancel_label);
interthread_progress_window->set_default_size (200, 100);
}
void
Editor::interthread_cancel_clicked ()
{
if (current_interthread_info) {
current_interthread_info->cancel = true;
}
}
void
Editor::region_from_selection ()
{
@ -3640,13 +3607,6 @@ Editor::freeze_thread ()
return 0;
}
gint
Editor::freeze_progress_timeout (void */*arg*/)
{
interthread_progress_bar.set_fraction (current_interthread_info->progress);
return !(current_interthread_info->done || current_interthread_info->cancel);
}
void
Editor::freeze_route ()
{
@ -3655,21 +3615,9 @@ Editor::freeze_route ()
}
InterThreadInfo itt;
if (interthread_progress_window == 0) {
build_interthread_progress_window ();
}
interthread_progress_window->set_title (_("Freeze"));
interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
interthread_progress_window->show_all ();
interthread_progress_bar.set_fraction (0.0f);
interthread_progress_label.set_text ("");
interthread_cancel_label.set_text (_("Cancel Freeze"));
current_interthread_info = &itt;
interthread_progress_connection =
Glib::signal_timeout().connect (sigc::bind (sigc::mem_fun(*this, &Editor::freeze_progress_timeout), (gpointer) 0), 100);
InterthreadProgressWindow ipw (current_interthread_info, _("Freeze"), _("Cancel Freeze"));
itt.done = false;
itt.cancel = false;
@ -3683,8 +3631,6 @@ Editor::freeze_route ()
gtk_main_iteration ();
}
interthread_progress_connection.disconnect ();
interthread_progress_window->hide_all ();
current_interthread_info = 0;
track_canvas->get_window()->set_cursor (*current_canvas_cursor);
}

View File

@ -0,0 +1,94 @@
/*
Copyright (C) 2010 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/main.h>
#include <gtkmm/stock.h>
#include "ardour/import_status.h"
#include "interthread_progress_window.h"
using namespace std;
using namespace Gtk;
/** @param i Status information.
* @param t Window title.
* @param c Label to use for Cancel button.
*/
InterthreadProgressWindow::InterthreadProgressWindow (ARDOUR::InterThreadInfo* i, string const & t, string const & c)
: ArdourDialog (t, true)
, _interthread_info (i)
{
_bar.set_orientation (Gtk::PROGRESS_LEFT_TO_RIGHT);
set_border_width (12);
get_vbox()->set_spacing (6);
get_vbox()->pack_start (_bar, false, false);
Button* b = add_button (Stock::CANCEL, RESPONSE_CANCEL);
b->signal_clicked().connect (sigc::mem_fun (*this, &InterthreadProgressWindow::cancel_clicked));
_cancel_label.set_text (c);
_cancel_button.add (_cancel_label);
set_default_size (200, 100);
show_all ();
Glib::signal_timeout().connect (sigc::mem_fun (*this, &InterthreadProgressWindow::update), 100);
}
void
InterthreadProgressWindow::cancel_clicked ()
{
_interthread_info->cancel = true;
}
bool
InterthreadProgressWindow::update ()
{
_bar.set_fraction (_interthread_info->progress);
return !(_interthread_info->done || _interthread_info->cancel);
}
/** @param i Status information.
* @param t Window title.
* @param c Label to use for Cancel button.
*/
ImportProgressWindow::ImportProgressWindow (ARDOUR::ImportStatus* s, string const & t, string const & c)
: InterthreadProgressWindow (s, t, c)
, _import_status (s)
{
_label.set_alignment (0, 0.5);
_label.set_use_markup (true);
get_vbox()->pack_start (_label, false, false);
_label.show ();
}
bool
ImportProgressWindow::update ()
{
_cancel_button.set_sensitive (!_import_status->freeze);
_label.set_markup ("<i>" + _import_status->doing_what + "</i>");
/* use overall progress for the bar, rather than that for individual files */
_bar.set_fraction ((_import_status->current - 1 + _import_status->progress) / _import_status->total);
return !(_import_status->done || _import_status->cancel);
}

View File

@ -0,0 +1,69 @@
/*
Copyright (C) 2010 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __ardour_interthread_progress_window_h__
#define __ardour_interthread_progress_window_h__
#include <gtkmm/label.h>
#include <gtkmm/progressbar.h>
#include "ardour_dialog.h"
namespace ARDOUR {
class InterThreadInfo;
class ImportStatus;
}
/** A progress dialogue which gets its status from an
* ARDOUR::InterThreadInfo struct. Displays a progress bar, which is
* automagically updated using a Glib timer, and a cancel button.
*/
class InterthreadProgressWindow : public ArdourDialog
{
public:
InterthreadProgressWindow (ARDOUR::InterThreadInfo *, std::string const &, std::string const &);
protected:
virtual bool update ();
Gtk::Button _cancel_button;
Gtk::Label _cancel_label;
Gtk::ProgressBar _bar;
private:
void cancel_clicked ();
ARDOUR::InterThreadInfo* _interthread_info;
};
/** Progress dialogue for importing sound files */
class ImportProgressWindow : public InterthreadProgressWindow
{
public:
ImportProgressWindow (ARDOUR::ImportStatus *, std::string const &, std::string const &);
private:
bool update ();
Gtk::Label _label;
ARDOUR::ImportStatus* _import_status;
};
#endif

View File

@ -116,6 +116,7 @@ gtk2_ardour_sources = [
'group_tabs.cc',
'gtk-custom-hruler.c',
'gtk-custom-ruler.c',
'interthread_progress_window.cc',
'io_selector.cc',
'keyboard.cc',
'keyeditor.cc',

View File

@ -250,16 +250,13 @@ compose_status_message (const string& path,
uint total_files)
{
if (file_samplerate != session_samplerate) {
return string_compose (_("<b>Resampling</b> from %1kHz to %2kHz.\n<i>%3</i>\n(%4 of %5)"),
file_samplerate/1000.0f,
session_samplerate/1000.0f,
return string_compose (_("Resampling %1 from %2kHz to %3kHz"),
Glib::path_get_basename (path),
current_file, total_files);
file_samplerate/1000.0f,
session_samplerate/1000.0f);
}
return string_compose (_("<b>Copying</b>\n<i>%1</i>\n(%2 of %3)"),
Glib::path_get_basename (path),
current_file, total_files);
return string_compose (_("Copying %1"), Glib::path_get_basename (path));
}
static void
@ -517,6 +514,7 @@ Session::import_audiofiles (ImportStatus& status)
}
++status.current;
status.progress = 0;
}
if (!status.cancel) {