21 |
#include <cstring> |
#include <cstring> |
22 |
|
|
23 |
#include "compat.h" |
#include "compat.h" |
|
// threads.h must be included first to be able to build with |
|
|
// G_DISABLE_DEPRECATED |
|
|
#if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \ |
|
|
(GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2 |
|
|
#include <glibmm/threads.h> |
|
|
#endif |
|
24 |
|
|
25 |
#include <glibmm/convert.h> |
#include <glibmm/convert.h> |
26 |
#include <glibmm/dispatcher.h> |
#include <glibmm/dispatcher.h> |
96 |
|
|
97 |
if (!Settings::singleton()->autoRestoreWindowDimension) { |
if (!Settings::singleton()->autoRestoreWindowDimension) { |
98 |
#if GTKMM_MAJOR_VERSION >= 3 |
#if GTKMM_MAJOR_VERSION >= 3 |
99 |
set_default_size(895, 600); |
set_default_size(960, 600); |
100 |
#else |
#else |
101 |
set_default_size(800, 600); |
set_default_size(865, 600); |
102 |
#endif |
#endif |
103 |
set_position(Gtk::WIN_POS_CENTER); |
set_position(Gtk::WIN_POS_CENTER); |
104 |
} |
} |
1888 |
|
|
1889 |
|
|
1890 |
LoaderSaverBase::LoaderSaverBase(const Glib::ustring filename, gig::File* gig) : |
LoaderSaverBase::LoaderSaverBase(const Glib::ustring filename, gig::File* gig) : |
1891 |
filename(filename), gig(gig), thread(0), progress(0.f) |
filename(filename), gig(gig), |
1892 |
|
#ifdef GLIB_THREADS |
1893 |
|
thread(0), |
1894 |
|
#endif |
1895 |
|
progress(0.f) |
1896 |
{ |
{ |
1897 |
} |
} |
1898 |
|
|
1905 |
void LoaderSaverBase::progress_callback(float fraction) |
void LoaderSaverBase::progress_callback(float fraction) |
1906 |
{ |
{ |
1907 |
{ |
{ |
1908 |
|
#ifdef GLIB_THREADS |
1909 |
Glib::Threads::Mutex::Lock lock(progressMutex); |
Glib::Threads::Mutex::Lock lock(progressMutex); |
1910 |
|
#else |
1911 |
|
std::lock_guard<std::mutex> lock(progressMutex); |
1912 |
|
#endif |
1913 |
progress = fraction; |
progress = fraction; |
1914 |
} |
} |
1915 |
progress_dispatcher(); |
progress_dispatcher(); |
1921 |
#endif |
#endif |
1922 |
void LoaderSaverBase::thread_function() |
void LoaderSaverBase::thread_function() |
1923 |
{ |
{ |
1924 |
|
#ifdef GLIB_THREADS |
1925 |
printf("thread_function self=%p\n", |
printf("thread_function self=%p\n", |
1926 |
static_cast<void*>(Glib::Threads::Thread::self())); |
static_cast<void*>(Glib::Threads::Thread::self())); |
1927 |
|
#else |
1928 |
|
std::cout << "thread_function self=" << std::this_thread::get_id() << "\n"; |
1929 |
|
#endif |
1930 |
printf("Start %s\n", filename.c_str()); |
printf("Start %s\n", filename.c_str()); |
1931 |
try { |
try { |
1932 |
gig::progress_t progress; |
gig::progress_t progress; |
1947 |
|
|
1948 |
void LoaderSaverBase::launch() |
void LoaderSaverBase::launch() |
1949 |
{ |
{ |
1950 |
|
#ifdef GLIB_THREADS |
1951 |
#ifdef OLD_THREADS |
#ifdef OLD_THREADS |
1952 |
thread = Glib::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function), true); |
thread = Glib::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function), true); |
1953 |
#else |
#else |
1954 |
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function)); |
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function)); |
1955 |
#endif |
#endif |
1956 |
printf("launch thread=%p\n", static_cast<void*>(thread)); |
printf("launch thread=%p\n", static_cast<void*>(thread)); |
1957 |
|
#else |
1958 |
|
thread = std::thread([this](){ thread_function(); }); |
1959 |
|
std::cout << "launch thread=" << thread.get_id() << "\n"; |
1960 |
|
#endif |
1961 |
} |
} |
1962 |
|
|
1963 |
float LoaderSaverBase::get_progress() |
float LoaderSaverBase::get_progress() |
1964 |
{ |
{ |
1965 |
|
#ifdef GLIB_THREADS |
1966 |
Glib::Threads::Mutex::Lock lock(progressMutex); |
Glib::Threads::Mutex::Lock lock(progressMutex); |
1967 |
|
#else |
1968 |
|
std::lock_guard<std::mutex> lock(progressMutex); |
1969 |
|
#endif |
1970 |
return progress; |
return progress; |
1971 |
} |
} |
1972 |
|
|
1985 |
return error_dispatcher; |
return error_dispatcher; |
1986 |
} |
} |
1987 |
|
|
1988 |
|
void LoaderSaverBase::join() { |
1989 |
|
#ifdef GLIB_THREADS |
1990 |
|
thread->join(); |
1991 |
|
#else |
1992 |
|
thread.join(); |
1993 |
|
#endif |
1994 |
|
} |
1995 |
|
|
1996 |
|
|
1997 |
Loader::Loader(const char* filename) : |
Loader::Loader(const char* filename) : |
1998 |
LoaderSaverBase(filename, 0) |
LoaderSaverBase(filename, 0) |
2205 |
dialog.set_current_folder(current_gig_dir); |
dialog.set_current_folder(current_gig_dir); |
2206 |
} |
} |
2207 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
2208 |
|
dialog.hide(); |
2209 |
std::string filename = dialog.get_filename(); |
std::string filename = dialog.get_filename(); |
2210 |
printf("filename=%s\n", filename.c_str()); |
printf("filename=%s\n", filename.c_str()); |
2211 |
|
#ifdef GLIB_THREADS |
2212 |
printf("on_action_file_open self=%p\n", |
printf("on_action_file_open self=%p\n", |
2213 |
static_cast<void*>(Glib::Threads::Thread::self())); |
static_cast<void*>(Glib::Threads::Thread::self())); |
2214 |
|
#else |
2215 |
|
std::cout << "on_action_file_open self=" << |
2216 |
|
std::this_thread::get_id() << "\n"; |
2217 |
|
#endif |
2218 |
load_file(filename.c_str()); |
load_file(filename.c_str()); |
2219 |
current_gig_dir = Glib::path_get_dirname(filename); |
current_gig_dir = Glib::path_get_dirname(filename); |
2220 |
} |
} |
2287 |
|
|
2288 |
void MainWindow::on_loader_finished() |
void MainWindow::on_loader_finished() |
2289 |
{ |
{ |
2290 |
|
loader->join(); |
2291 |
printf("Loader finished!\n"); |
printf("Loader finished!\n"); |
2292 |
|
#ifdef GLIB_THREADS |
2293 |
printf("on_loader_finished self=%p\n", |
printf("on_loader_finished self=%p\n", |
2294 |
static_cast<void*>(Glib::Threads::Thread::self())); |
static_cast<void*>(Glib::Threads::Thread::self())); |
2295 |
|
#else |
2296 |
|
std::cout << "on_loader_finished self=" << |
2297 |
|
std::this_thread::get_id() << "\n"; |
2298 |
|
#endif |
2299 |
load_gig(loader->gig, loader->filename.c_str()); |
load_gig(loader->gig, loader->filename.c_str()); |
2300 |
progress_dialog->hide(); |
progress_dialog->hide(); |
2301 |
} |
} |
2302 |
|
|
2303 |
void MainWindow::on_loader_error() |
void MainWindow::on_loader_error() |
2304 |
{ |
{ |
2305 |
|
loader->join(); |
2306 |
Glib::ustring txt = _("Could not load file: ") + loader->error_message; |
Glib::ustring txt = _("Could not load file: ") + loader->error_message; |
2307 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
2308 |
msg.run(); |
msg.run(); |
2373 |
|
|
2374 |
void MainWindow::on_saver_error() |
void MainWindow::on_saver_error() |
2375 |
{ |
{ |
2376 |
|
saver->join(); |
2377 |
file_structure_changed_signal.emit(this->file); |
file_structure_changed_signal.emit(this->file); |
2378 |
Glib::ustring txt = _("Could not save file: ") + saver->error_message; |
Glib::ustring txt = _("Could not save file: ") + saver->error_message; |
2379 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
2382 |
|
|
2383 |
void MainWindow::on_saver_finished() |
void MainWindow::on_saver_finished() |
2384 |
{ |
{ |
2385 |
|
saver->join(); |
2386 |
this->file = saver->gig; |
this->file = saver->gig; |
2387 |
this->filename = saver->filename; |
this->filename = saver->filename; |
2388 |
current_gig_dir = Glib::path_get_dirname(filename); |
current_gig_dir = Glib::path_get_dirname(filename); |
2474 |
#endif |
#endif |
2475 |
|
|
2476 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
2477 |
|
dialog.hide(); |
2478 |
std::string filename = dialog.get_filename(); |
std::string filename = dialog.get_filename(); |
2479 |
if (!Glib::str_has_suffix(filename, ".gig")) { |
if (!Glib::str_has_suffix(filename, ".gig")) { |
2480 |
filename += ".gig"; |
filename += ".gig"; |
2666 |
"backup your Gigasampler/GigaStudio files before editing them with " |
"backup your Gigasampler/GigaStudio files before editing them with " |
2667 |
"this application.\n" |
"this application.\n" |
2668 |
"\n" |
"\n" |
2669 |
"Please report bugs to: http://bugs.linuxsampler.org" |
"Please report bugs to: https://bugs.linuxsampler.org" |
2670 |
); |
); |
2671 |
dialog.set_comments(sComment.c_str()); |
dialog.set_comments(sComment.c_str()); |
2672 |
dialog.set_website("http://www.linuxsampler.org"); |
dialog.set_website("https://www.linuxsampler.org"); |
2673 |
dialog.set_website_label("http://www.linuxsampler.org"); |
dialog.set_website_label("https://www.linuxsampler.org"); |
2674 |
dialog.set_position(Gtk::WIN_POS_CENTER); |
dialog.set_position(Gtk::WIN_POS_CENTER); |
2675 |
dialog.run(); |
dialog.run(); |
2676 |
} |
} |
4111 |
dialog.set_current_folder(current_sample_dir); |
dialog.set_current_folder(current_sample_dir); |
4112 |
} |
} |
4113 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
4114 |
|
dialog.hide(); |
4115 |
current_sample_dir = dialog.get_current_folder(); |
current_sample_dir = dialog.get_current_folder(); |
4116 |
Glib::ustring error_files; |
Glib::ustring error_files; |
4117 |
std::vector<std::string> filenames = dialog.get_filenames(); |
std::vector<std::string> filenames = dialog.get_filenames(); |
4292 |
} |
} |
4293 |
if (dialog.run() == Gtk::RESPONSE_OK) |
if (dialog.run() == Gtk::RESPONSE_OK) |
4294 |
{ |
{ |
4295 |
|
dialog.hide(); |
4296 |
current_sample_dir = dialog.get_current_folder(); |
current_sample_dir = dialog.get_current_folder(); |
4297 |
Glib::ustring error_files; |
Glib::ustring error_files; |
4298 |
std::string folder = dialog.get_filename(); |
std::string folder = dialog.get_filename(); |
5021 |
#endif |
#endif |
5022 |
|
|
5023 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
5024 |
|
dialog.hide(); |
5025 |
|
#ifdef GLIB_THREADS |
5026 |
printf("on_action_merge_files self=%p\n", |
printf("on_action_merge_files self=%p\n", |
5027 |
static_cast<void*>(Glib::Threads::Thread::self())); |
static_cast<void*>(Glib::Threads::Thread::self())); |
5028 |
|
#else |
5029 |
|
std::cout << "on_action_merge_files self=" << |
5030 |
|
std::this_thread::get_id() << "\n"; |
5031 |
|
#endif |
5032 |
std::vector<std::string> filenames = dialog.get_filenames(); |
std::vector<std::string> filenames = dialog.get_filenames(); |
5033 |
|
|
5034 |
// merge the selected files to the currently open .gig file |
// merge the selected files to the currently open .gig file |