1892 |
} |
} |
1893 |
} |
} |
1894 |
|
|
1895 |
|
|
1896 |
|
LoaderSaverBase::LoaderSaverBase(const Glib::ustring filename, gig::File* gig) : |
1897 |
|
filename(filename), gig(gig), thread(0), progress(0.f) |
1898 |
|
{ |
1899 |
|
} |
1900 |
|
|
1901 |
void loader_progress_callback(gig::progress_t* progress) |
void loader_progress_callback(gig::progress_t* progress) |
1902 |
{ |
{ |
1903 |
Loader* loader = static_cast<Loader*>(progress->custom); |
LoaderSaverBase* loader = static_cast<LoaderSaverBase*>(progress->custom); |
1904 |
loader->progress_callback(progress->factor); |
loader->progress_callback(progress->factor); |
1905 |
} |
} |
1906 |
|
|
1907 |
void Loader::progress_callback(float fraction) |
void LoaderSaverBase::progress_callback(float fraction) |
1908 |
{ |
{ |
1909 |
{ |
{ |
1910 |
Glib::Threads::Mutex::Lock lock(progressMutex); |
Glib::Threads::Mutex::Lock lock(progressMutex); |
1917 |
// make sure stack is 16-byte aligned for SSE instructions |
// make sure stack is 16-byte aligned for SSE instructions |
1918 |
__attribute__((force_align_arg_pointer)) |
__attribute__((force_align_arg_pointer)) |
1919 |
#endif |
#endif |
1920 |
void Loader::thread_function() |
void LoaderSaverBase::thread_function() |
1921 |
{ |
{ |
1922 |
printf("thread_function self=%p\n", |
printf("thread_function self=%p\n", |
1923 |
static_cast<void*>(Glib::Threads::Thread::self())); |
static_cast<void*>(Glib::Threads::Thread::self())); |
1924 |
printf("Start %s\n", filename.c_str()); |
printf("Start %s\n", filename.c_str()); |
1925 |
try { |
try { |
|
RIFF::File* riff = new RIFF::File(filename); |
|
|
gig = new gig::File(riff); |
|
1926 |
gig::progress_t progress; |
gig::progress_t progress; |
1927 |
progress.callback = loader_progress_callback; |
progress.callback = loader_progress_callback; |
1928 |
progress.custom = this; |
progress.custom = this; |
1929 |
|
|
1930 |
gig->GetInstrument(0, &progress); |
thread_function_sub(progress); |
1931 |
printf("End\n"); |
printf("End\n"); |
1932 |
finished_dispatcher(); |
finished_dispatcher(); |
1933 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
1939 |
} |
} |
1940 |
} |
} |
1941 |
|
|
1942 |
Loader::Loader(const char* filename) |
void LoaderSaverBase::launch() |
|
: filename(filename), gig(0), thread(0), progress(0.f) |
|
|
{ |
|
|
} |
|
|
|
|
|
void Loader::launch() |
|
1943 |
{ |
{ |
1944 |
#ifdef OLD_THREADS |
#ifdef OLD_THREADS |
1945 |
thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true); |
thread = Glib::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function), true); |
1946 |
#else |
#else |
1947 |
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function)); |
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function)); |
1948 |
#endif |
#endif |
1949 |
printf("launch thread=%p\n", static_cast<void*>(thread)); |
printf("launch thread=%p\n", static_cast<void*>(thread)); |
1950 |
} |
} |
1951 |
|
|
1952 |
float Loader::get_progress() |
float LoaderSaverBase::get_progress() |
1953 |
{ |
{ |
1954 |
float res; |
Glib::Threads::Mutex::Lock lock(progressMutex); |
1955 |
{ |
return progress; |
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
|
|
res = progress; |
|
|
} |
|
|
return res; |
|
1956 |
} |
} |
1957 |
|
|
1958 |
Glib::Dispatcher& Loader::signal_progress() |
Glib::Dispatcher& LoaderSaverBase::signal_progress() |
1959 |
{ |
{ |
1960 |
return progress_dispatcher; |
return progress_dispatcher; |
1961 |
} |
} |
1962 |
|
|
1963 |
Glib::Dispatcher& Loader::signal_finished() |
Glib::Dispatcher& LoaderSaverBase::signal_finished() |
1964 |
{ |
{ |
1965 |
return finished_dispatcher; |
return finished_dispatcher; |
1966 |
} |
} |
1967 |
|
|
1968 |
Glib::Dispatcher& Loader::signal_error() |
Glib::Dispatcher& LoaderSaverBase::signal_error() |
1969 |
{ |
{ |
1970 |
return error_dispatcher; |
return error_dispatcher; |
1971 |
} |
} |
1972 |
|
|
|
void saver_progress_callback(gig::progress_t* progress) |
|
|
{ |
|
|
Saver* saver = static_cast<Saver*>(progress->custom); |
|
|
saver->progress_callback(progress->factor); |
|
|
} |
|
1973 |
|
|
1974 |
void Saver::progress_callback(float fraction) |
Loader::Loader(const char* filename) : |
1975 |
|
LoaderSaverBase(filename, 0) |
1976 |
{ |
{ |
|
{ |
|
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
|
|
progress = fraction; |
|
|
} |
|
|
progress_dispatcher.emit(); |
|
1977 |
} |
} |
1978 |
|
|
1979 |
#if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) |
void Loader::thread_function_sub(gig::progress_t& progress) |
|
// make sure stack is 16-byte aligned for SSE instructions |
|
|
__attribute__((force_align_arg_pointer)) |
|
|
#endif |
|
|
void Saver::thread_function() |
|
1980 |
{ |
{ |
1981 |
printf("thread_function self=%p\n", |
RIFF::File* riff = new RIFF::File(filename); |
1982 |
static_cast<void*>(Glib::Threads::Thread::self())); |
gig = new gig::File(riff); |
|
printf("Start %s\n", filename.c_str()); |
|
|
try { |
|
|
gig::progress_t progress; |
|
|
progress.callback = saver_progress_callback; |
|
|
progress.custom = this; |
|
|
|
|
|
// if no filename was provided, that means "save", if filename was provided means "save as" |
|
|
if (filename.empty()) { |
|
|
if (!Settings::singleton()->saveWithTemporaryFile) { |
|
|
// save directly over the existing .gig file |
|
|
// (requires less disk space than solution below |
|
|
// but may be slower) |
|
|
gig->Save(&progress); |
|
|
} else { |
|
|
// save the file as separate temporary file first, |
|
|
// then move the saved file over the old file |
|
|
// (may result in performance speedup during save) |
|
|
gig::String tmpname = filename + ".TMP"; |
|
|
gig->Save(tmpname, &progress); |
|
|
#if defined(WIN32) |
|
|
if (!DeleteFile(filename.c_str())) { |
|
|
throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file)."); |
|
|
} |
|
|
#else // POSIX ... |
|
|
if (unlink(filename.c_str())) { |
|
|
throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + gig::String(strerror(errno))); |
|
|
} |
|
|
#endif |
|
|
if (rename(tmpname.c_str(), filename.c_str())) { |
|
|
#if defined(WIN32) |
|
|
throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file)."); |
|
|
#else |
|
|
throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + gig::String(strerror(errno))); |
|
|
#endif |
|
|
} |
|
|
} |
|
|
} else { |
|
|
gig->Save(filename, &progress); |
|
|
} |
|
1983 |
|
|
1984 |
printf("End\n"); |
gig->GetInstrument(0, &progress); |
|
finished_dispatcher.emit(); |
|
|
} catch (RIFF::Exception e) { |
|
|
error_message = e.Message; |
|
|
error_dispatcher.emit(); |
|
|
} catch (...) { |
|
|
error_message = _("Unknown exception occurred"); |
|
|
error_dispatcher.emit(); |
|
|
} |
|
1985 |
} |
} |
1986 |
|
|
1987 |
Saver::Saver(gig::File* file, Glib::ustring filename) |
|
1988 |
: gig(file), filename(filename), thread(0), progress(0.f) |
Saver::Saver(gig::File* file, Glib::ustring filename) : |
1989 |
|
LoaderSaverBase(filename, file) |
1990 |
{ |
{ |
1991 |
} |
} |
1992 |
|
|
1993 |
void Saver::launch() |
void Saver::thread_function_sub(gig::progress_t& progress) |
1994 |
{ |
{ |
1995 |
#ifdef OLD_THREADS |
// if no filename was provided, that means "save", if filename was provided means "save as" |
1996 |
thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true); |
if (filename.empty()) { |
1997 |
|
if (!Settings::singleton()->saveWithTemporaryFile) { |
1998 |
|
// save directly over the existing .gig file |
1999 |
|
// (requires less disk space than solution below |
2000 |
|
// but may be slower) |
2001 |
|
gig->Save(&progress); |
2002 |
|
} else { |
2003 |
|
// save the file as separate temporary file first, |
2004 |
|
// then move the saved file over the old file |
2005 |
|
// (may result in performance speedup during save) |
2006 |
|
gig::String tmpname = filename + ".TMP"; |
2007 |
|
gig->Save(tmpname, &progress); |
2008 |
|
#if defined(WIN32) |
2009 |
|
if (!DeleteFile(filename.c_str())) { |
2010 |
|
throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file)."); |
2011 |
|
} |
2012 |
|
#else // POSIX ... |
2013 |
|
if (unlink(filename.c_str())) { |
2014 |
|
throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + gig::String(strerror(errno))); |
2015 |
|
} |
2016 |
|
#endif |
2017 |
|
if (rename(tmpname.c_str(), filename.c_str())) { |
2018 |
|
#if defined(WIN32) |
2019 |
|
throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file)."); |
2020 |
#else |
#else |
2021 |
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function)); |
throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + gig::String(strerror(errno))); |
2022 |
#endif |
#endif |
2023 |
printf("launch thread=%p\n", static_cast<void*>(thread)); |
} |
2024 |
} |
} |
2025 |
|
} else { |
2026 |
float Saver::get_progress() |
gig->Save(filename, &progress); |
|
{ |
|
|
float res; |
|
|
{ |
|
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
|
|
res = progress; |
|
2027 |
} |
} |
|
return res; |
|
|
} |
|
|
|
|
|
Glib::Dispatcher& Saver::signal_progress() |
|
|
{ |
|
|
return progress_dispatcher; |
|
|
} |
|
|
|
|
|
Glib::Dispatcher& Saver::signal_finished() |
|
|
{ |
|
|
return finished_dispatcher; |
|
2028 |
} |
} |
2029 |
|
|
|
Glib::Dispatcher& Saver::signal_error() |
|
|
{ |
|
|
return error_dispatcher; |
|
|
} |
|
2030 |
|
|
2031 |
ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent) |
ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent) |
2032 |
: Gtk::Dialog(title, parent, true) |
: Gtk::Dialog(title, parent, true) |
2670 |
set_title(_("File Properties")); |
set_title(_("File Properties")); |
2671 |
eName.set_width_chars(50); |
eName.set_width_chars(50); |
2672 |
|
|
2673 |
|
connect(eFileFormat, &PropDialog::set_FileFormat); |
2674 |
connect(eName, &DLS::Info::Name); |
connect(eName, &DLS::Info::Name); |
2675 |
connect(eCreationDate, &DLS::Info::CreationDate); |
connect(eCreationDate, &DLS::Info::CreationDate); |
2676 |
connect(eComments, &DLS::Info::Comments); |
connect(eComments, &DLS::Info::Comments); |
2732 |
quitButton.grab_focus(); |
quitButton.grab_focus(); |
2733 |
quitButton.signal_clicked().connect( |
quitButton.signal_clicked().connect( |
2734 |
sigc::mem_fun(*this, &PropDialog::hide)); |
sigc::mem_fun(*this, &PropDialog::hide)); |
|
eFileFormat.signal_value_changed().connect( |
|
|
sigc::mem_fun(*this, &PropDialog::onFileFormatChanged)); |
|
2735 |
|
|
2736 |
quitButton.show(); |
quitButton.show(); |
2737 |
vbox.show(); |
vbox.show(); |
2743 |
void PropDialog::set_file(gig::File* file) |
void PropDialog::set_file(gig::File* file) |
2744 |
{ |
{ |
2745 |
m_file = file; |
m_file = file; |
2746 |
|
update(file->pInfo); |
2747 |
|
|
2748 |
// update file format version combo box |
// update file format version combo box |
2749 |
const std::string sGiga = "Gigasampler/GigaStudio v"; |
const std::string sGiga = "Gigasampler/GigaStudio v"; |
2759 |
std::vector<const char*> texts; |
std::vector<const char*> texts; |
2760 |
for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str()); |
for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str()); |
2761 |
texts.push_back(NULL); values.push_back(0); |
texts.push_back(NULL); values.push_back(0); |
2762 |
|
|
2763 |
|
update_model++; |
2764 |
eFileFormat.set_choices(&texts[0], &values[0]); |
eFileFormat.set_choices(&texts[0], &values[0]); |
2765 |
eFileFormat.set_value(major); |
eFileFormat.set_value(major); |
2766 |
|
update_model--; |
2767 |
} |
} |
2768 |
|
|
2769 |
void PropDialog::onFileFormatChanged() { |
void PropDialog::set_FileFormat(int value) |
|
const int major = eFileFormat.get_value(); |
|
|
if (m_file) m_file->pVersion->major = major; |
|
|
} |
|
|
|
|
|
void PropDialog::set_info(DLS::Info* info) |
|
2770 |
{ |
{ |
2771 |
update(info); |
m_file->pVersion->major = value; |
2772 |
} |
} |
2773 |
|
|
2774 |
|
|
3004 |
file_is_changed = false; |
file_is_changed = false; |
3005 |
|
|
3006 |
propDialog.set_file(gig); |
propDialog.set_file(gig); |
|
propDialog.set_info(gig->pInfo); |
|
3007 |
|
|
3008 |
instrument_name_connection.block(); |
instrument_name_connection.block(); |
3009 |
int index = 0; |
int index = 0; |