/[svn]/gigedit/trunk/src/mainwindow.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/mainwindow.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1088 by persson, Sat Mar 10 08:16:38 2007 UTC revision 1096 by schoenebeck, Tue Mar 13 17:14:38 2007 UTC
# Line 28  Line 28 
28  #define ABOUT_DIALOG  #define ABOUT_DIALOG
29  #include <gtkmm/aboutdialog.h>  #include <gtkmm/aboutdialog.h>
30  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
31    #include <gtkmm/targetentry.h>
32  #endif  #endif
33    
34  #include <stdio.h>  #include <stdio.h>
# Line 390  void MainWindow::addProp(LabelWidget& pr Line 391  void MainWindow::addProp(LabelWidget& pr
391    
392  MainWindow::MainWindow() :  MainWindow::MainWindow() :
393  //    eSample("Sample", wSample),  //    eSample("Sample", wSample),
     eVelocityUpperLimit("VelocityUpperLimit",  
                         &gig::DimensionRegion::VelocityUpperLimit),  
394      eEG1PreAttack("PreAttack", &gig::DimensionRegion::EG1PreAttack, 0, 100, 2),      eEG1PreAttack("PreAttack", &gig::DimensionRegion::EG1PreAttack, 0, 100, 2),
395      eEG1Attack("Attack", &gig::DimensionRegion::EG1Attack, 0, 60, 3),      eEG1Attack("Attack", &gig::DimensionRegion::EG1Attack, 0, 60, 3),
396      eEG1Decay1("Decay1", &gig::DimensionRegion::EG1Decay1, 0.005, 60, 3),      eEG1Decay1("Decay1", &gig::DimensionRegion::EG1Decay1, 0.005, 60, 3),
# Line 552  MainWindow::MainWindow() : Line 551  MainWindow::MainWindow() :
551      firstRowInBlock = 0;      firstRowInBlock = 0;
552    
553      addString("Sample", lSample, wSample);      addString("Sample", lSample, wSample);
554      addProp(eVelocityUpperLimit);      //TODO: the following would break drag&drop:   wSample->property_editable().set_value(false);  or this:    wSample->set_editable(false);
555      addHeader("EG1");      addHeader("EG1");
556      addProp(eEG1PreAttack);      addProp(eEG1PreAttack);
557      addProp(eEG1Attack);      addProp(eEG1Attack);
# Line 931  MainWindow::MainWindow() : Line 930  MainWindow::MainWindow() :
930      m_TreeView.set_headers_visible(false);      m_TreeView.set_headers_visible(false);
931    
932      // create samples treeview (including its data model)      // create samples treeview (including its data model)
933      m_refSamplesTreeModel = Gtk::TreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
934      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
935      m_TreeViewSamples.append_column("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column("Samples", m_SamplesModel.m_col_name);
936      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.set_headers_visible(false);
# Line 939  MainWindow::MainWindow() : Line 938  MainWindow::MainWindow() :
938          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
939      );      );
940    
941        // establish drag&drop between samples tree view and dimension region 'Sample' text entry
942        std::list<Gtk::TargetEntry> drag_target_gig_sample;
943        drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") );
944    //drag_target_gig_sample.push_back( Gtk::TargetEntry("STRING") );
945    //drag_target_gig_sample.push_back( Gtk::TargetEntry("text/plain") );
946        m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
947        m_TreeViewSamples.signal_drag_data_get().connect(
948            sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_data_get)
949        );
950        wSample->drag_dest_set(drag_target_gig_sample);
951        wSample->signal_drag_data_received().connect(
952            sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received)
953        );
954    
955      file = 0;      file = 0;
956    
957      show_all_children();      show_all_children();
# Line 977  void MainWindow::set_dim_region(gig::Dim Line 990  void MainWindow::set_dim_region(gig::Dim
990  {  {
991      update_gui = false;      update_gui = false;
992      wSample->set_text(d->pSample ? d->pSample->pInfo->Name.c_str() : "NULL");      wSample->set_text(d->pSample ? d->pSample->pInfo->Name.c_str() : "NULL");
     eVelocityUpperLimit.set_dimreg(d);  
993      eEG1PreAttack.set_dimreg(d);      eEG1PreAttack.set_dimreg(d);
994      eEG1Attack.set_dimreg(d);      eEG1Attack.set_dimreg(d);
995      eEG1Decay1.set_dimreg(d);      eEG1Decay1.set_dimreg(d);
# Line 1349  void MainWindow::on_loader_finished() Line 1361  void MainWindow::on_loader_finished()
1361  void MainWindow::on_action_file_save()  void MainWindow::on_action_file_save()
1362  {  {
1363      if (!file) return;      if (!file) return;
1364      file->Save();      std::cout << "Saving file\n" << std::flush;
1365        try {
1366            file->Save();
1367        } catch (RIFF::Exception e) {
1368            Glib::ustring txt = "Could not save file: " + e.Message;
1369            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1370            msg.run();
1371            return;
1372        }
1373        std::cout << "Saving file done\n" << std::flush;
1374      __import_queued_samples();      __import_queued_samples();
1375  }  }
1376    
# Line 1364  void MainWindow::on_action_file_save_as( Line 1385  void MainWindow::on_action_file_save_as(
1385      dialog.set_filter(filter);      dialog.set_filter(filter);
1386      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1387          printf("filename=%s\n", dialog.get_filename().c_str());          printf("filename=%s\n", dialog.get_filename().c_str());
1388          file->Save(dialog.get_filename());          try {
1389                file->Save(dialog.get_filename());
1390            } catch (RIFF::Exception e) {
1391                Glib::ustring txt = "Could not save file: " + e.Message;
1392                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1393                msg.run();
1394                return;
1395            }
1396          __import_queued_samples();          __import_queued_samples();
1397      }      }
1398  }  }
1399    
1400  // actually write the sample(s)' data to the gig file  // actually write the sample(s)' data to the gig file
1401  void MainWindow::__import_queued_samples() {  void MainWindow::__import_queued_samples() {
1402        std::cout << "Starting sample import\n" << std::flush;
1403      Glib::ustring error_files;      Glib::ustring error_files;
1404      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); iter != m_SampleImportQueue.end(); ++iter) {      printf("Samples to import: %d\n", m_SampleImportQueue.size());
1405        for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); iter != m_SampleImportQueue.end(); ) {
1406          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",(*iter).sample_path.c_str());
1407          SF_INFO info;          SF_INFO info;
1408          info.format = 0;          info.format = 0;
# Line 1426  void MainWindow::__import_queued_samples Line 1456  void MainWindow::__import_queued_samples
1456              sf_close(hFile);              sf_close(hFile);
1457              delete buffer;              delete buffer;
1458              // on success we remove the sample from the import queue, otherwise keep it, maybe it works the next time ?              // on success we remove the sample from the import queue, otherwise keep it, maybe it works the next time ?
1459              m_SampleImportQueue.erase(iter);              std::list<SampleImportItem>::iterator cur = iter;
1460                ++iter;
1461                m_SampleImportQueue.erase(cur);
1462          } catch (std::string what) { // remember the files that made trouble (and their cause)          } catch (std::string what) { // remember the files that made trouble (and their cause)
1463              if (error_files.size()) error_files += "\n";              if (error_files.size()) error_files += "\n";
1464              error_files += (*iter).sample_path += " (" + what + ")";              error_files += (*iter).sample_path += " (" + what + ")";
1465                ++iter;
1466          }          }
1467      }      }
1468      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
# Line 1749  void MainWindow::on_action_add_sample() Line 1782  void MainWindow::on_action_add_sample()
1782      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1783      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1784      dialog.set_select_multiple(true);      dialog.set_select_multiple(true);
1785      Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile (yet to do ;-)      Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile
1786      soundfilter.add_pattern("*.wav");      const char* supportedFileTypes[] = {
1787            "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",
1788            "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",
1789            "*.svx", "*.SVX", "*.sf", "*.SF", "*.voc", "*.VOC", "*.w64",
1790            "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",
1791            "*.caf", "*.CAF", NULL
1792        };
1793        for (int i = 0; supportedFileTypes[i]; i++)
1794            soundfilter.add_pattern(supportedFileTypes[i]);
1795      soundfilter.set_name("Sound Files");      soundfilter.set_name("Sound Files");
1796      Gtk::FileFilter allpassfilter; // matches every file      Gtk::FileFilter allpassfilter; // matches every file
1797      allpassfilter.add_pattern("*.*");      allpassfilter.add_pattern("*.*");
# Line 1804  void MainWindow::on_action_add_sample() Line 1845  void MainWindow::on_action_add_sample()
1845                  sample->SamplesPerSecond = info.samplerate;                  sample->SamplesPerSecond = info.samplerate;
1846                  // schedule resizing the sample (which will be done physically when File::Save() is called)                  // schedule resizing the sample (which will be done physically when File::Save() is called)
1847                  sample->Resize(info.frames);                  sample->Resize(info.frames);
1848                    // make sure sample is part of the selected group
1849                    group->AddSample(sample);
1850                  // schedule that physical resize and sample import (data copying), performed when "Save" is requested                  // schedule that physical resize and sample import (data copying), performed when "Save" is requested
1851                  SampleImportItem sched_item;                  SampleImportItem sched_item;
1852                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
# Line 1839  void MainWindow::on_action_remove_sample Line 1882  void MainWindow::on_action_remove_sample
1882          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1883          gig::Group* group   = row[m_SamplesModel.m_col_group];          gig::Group* group   = row[m_SamplesModel.m_col_group];
1884          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          gig::Sample* sample = row[m_SamplesModel.m_col_sample];
1885            Glib::ustring name  = row[m_SamplesModel.m_col_name];
1886          try {          try {
1887              // remove group or sample from the gig file              // remove group or sample from the gig file
1888              if (group) {              if (group) {
1889                    // temporarily remember the samples that bolong to that group (we need that to clean the queue)
1890                    std::list<gig::Sample*> members;
1891                    for (gig::Sample* pSample = group->GetFirstSample(); pSample; pSample = group->GetNextSample()) {
1892                        members.push_back(pSample);
1893                    }
1894                    // delete the group in the .gig file including the samples that belong to the group
1895                  file->DeleteGroup(group);                  file->DeleteGroup(group);
1896                    // if sample(s) were just previously added, remove them from the import queue
1897                    for (std::list<gig::Sample*>::iterator member = members.begin(); member != members.end(); ++member) {
1898                        for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); iter != m_SampleImportQueue.end(); ++iter) {
1899                            if ((*iter).gig_sample == *member) {
1900                                printf("Removing previously added sample '%s' from group '%s'\n", (*iter).sample_path.c_str(), name.c_str());
1901                                m_SampleImportQueue.erase(iter);
1902                                break;
1903                            }
1904                        }
1905                    }
1906              } else if (sample) {              } else if (sample) {
1907                    // remove sample from the .gig file
1908                  file->DeleteSample(sample);                  file->DeleteSample(sample);
1909              }                  // if sample was just previously added, remove it from the import queue
             // if sample was just previously added, remove it from the import queue  
             if (sample) {  
1910                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); iter != m_SampleImportQueue.end(); ++iter) {                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); iter != m_SampleImportQueue.end(); ++iter) {
1911                      if ((*iter).gig_sample == sample) {                      if ((*iter).gig_sample == sample) {
1912                            printf("Removing previously added sample '%s'\n", (*iter).sample_path.c_str());
1913                          m_SampleImportQueue.erase(iter);                          m_SampleImportQueue.erase(iter);
1914                          break;                          break;
1915                      }                      }
# Line 1863  void MainWindow::on_action_remove_sample Line 1923  void MainWindow::on_action_remove_sample
1923          }          }
1924      }      }
1925  }  }
1926    
1927    void MainWindow::on_sample_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, Gtk::SelectionData& selection_data, guint, guint)
1928    {
1929        // get selected sample
1930        gig::Sample* sample = NULL;
1931        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
1932        Gtk::TreeModel::iterator it = sel->get_selected();
1933        if (it) {
1934            Gtk::TreeModel::Row row = *it;
1935            sample = row[m_SamplesModel.m_col_sample];
1936        }
1937        // pass the gig::Sample as pointer
1938        selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample, sizeof(sample)/*length of data in bytes*/);
1939    }
1940    
1941    void MainWindow::on_sample_label_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time)
1942    {
1943        gig::DimensionRegion* dimregion = m_DimRegionChooser.get_dimregion();
1944        gig::Sample* sample = *((gig::Sample**) selection_data.get_data());
1945    
1946        if (sample && dimregion && selection_data.get_length() == sizeof(gig::Sample*)) {
1947            if (sample != dimregion->pSample) {
1948                dimregion->pSample = sample;
1949                wSample->set_text(dimregion->pSample->pInfo->Name.c_str());
1950                std::cout << "Drop received sample \"" << dimregion->pSample->pInfo->Name.c_str() << "\"" << std::endl;
1951                // drop success
1952                context->drop_reply(true, time);
1953                return;
1954            }
1955        }
1956        // drop failed
1957        context->drop_reply(false, time);
1958    }

Legend:
Removed from v.1088  
changed lines
  Added in v.1096

  ViewVC Help
Powered by ViewVC