/[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 1082 by schoenebeck, Thu Mar 8 01:43:18 2007 UTC revision 1096 by schoenebeck, Tue Mar 13 17:14:38 2007 UTC
# Line 27  Line 27 
27  #if GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6  #if GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6
28  #define ABOUT_DIALOG  #define ABOUT_DIALOG
29  #include <gtkmm/aboutdialog.h>  #include <gtkmm/aboutdialog.h>
30    #include <gtkmm/messagedialog.h>
31    #include <gtkmm/targetentry.h>
32  #endif  #endif
33    
34    #include <stdio.h>
35    #include <sndfile.h>
36    
37  #define _(String) gettext(String)  #define _(String) gettext(String)
38    
39  template<class T> inline std::string ToString(T o) {  template<class T> inline std::string ToString(T o) {
# Line 386  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 516  MainWindow::MainWindow() : Line 519  MainWindow::MainWindow() :
519      eSampleLoops("SampleLoops", &access_SampleLoops, 0, 1)      eSampleLoops("SampleLoops", &access_SampleLoops, 0, 1)
520  {  {
521  //    set_border_width(5);  //    set_border_width(5);
522      set_default_size(400, 200);  //    set_default_size(400, 200);
523    
524    
525      add(m_VBox);      add(m_VBox);
# Line 530  MainWindow::MainWindow() : Line 533  MainWindow::MainWindow() :
533          sigc::mem_fun(*this, &MainWindow::on_button_release));          sigc::mem_fun(*this, &MainWindow::on_button_release));
534    
535      // Add the TreeView tab, inside a ScrolledWindow, with the button underneath:      // Add the TreeView tab, inside a ScrolledWindow, with the button underneath:
536      m_ScrolledWindow.add(m_TreeViewNotebook);      m_ScrolledWindow.add(m_TreeView);
537      m_ScrolledWindow.set_size_request(400, 600);  //    m_ScrolledWindow.set_size_request(200, 600);
538      m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
539    
540        m_ScrolledWindowSamples.add(m_TreeViewSamples);
541        m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
542    
543    
544      for (int i = 0 ; i < 5 ; i++) {      for (int i = 0 ; i < 5 ; i++) {
545          table[i] = new Gtk::Table(3, 1);          table[i] = new Gtk::Table(3, 1);
546          table[i]->set_col_spacings(5);          table[i]->set_col_spacings(5);
# Line 544  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 783  MainWindow::MainWindow() : Line 790  MainWindow::MainWindow() :
790      m_Notebook.append_page(*table[2], "EG3");      m_Notebook.append_page(*table[2], "EG3");
791      m_Notebook.append_page(*table[3], "Velocity");      m_Notebook.append_page(*table[3], "Velocity");
792      m_Notebook.append_page(*table[4], "Misc");      m_Notebook.append_page(*table[4], "Misc");
793      m_Notebook.set_size_request(400, 500);  //    m_Notebook.set_size_request(400, 500);
794    
795      m_HPaned.add1(m_ScrolledWindow);      m_TreeViewNotebook.set_size_request(300);
796        m_HPaned.add1(m_TreeViewNotebook);
797      m_HPaned.add2(m_Notebook);      m_HPaned.add2(m_Notebook);
798    
799    
800      m_TreeViewNotebook.append_page(m_TreeViewSamples, "Samples");      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, "Samples");
801      m_TreeViewNotebook.append_page(m_TreeView, "Instruments");      m_TreeViewNotebook.append_page(m_ScrolledWindow, "Instruments");
802    
803    
804      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
# Line 851  MainWindow::MainWindow() : Line 859  MainWindow::MainWindow() :
859          sigc::mem_fun(*this, &MainWindow::on_action_add_group)          sigc::mem_fun(*this, &MainWindow::on_action_add_group)
860      );      );
861      actionGroup->add(      actionGroup->add(
862          Gtk::Action::create("AddSample", _("Add _Sample")),          Gtk::Action::create("AddSample", _("Add _Sample(s)")),
863          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
864      );      );
865      actionGroup->add(      actionGroup->add(
# Line 922  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 930  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 968  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 1276  LoadDialog::LoadDialog() Line 1297  LoadDialog::LoadDialog()
1297    
1298  void MainWindow::on_action_file_new()  void MainWindow::on_action_file_new()
1299  {  {
1300        m_SampleImportQueue.clear();
1301  }  }
1302    
1303  void MainWindow::on_action_file_open()  void MainWindow::on_action_file_open()
# Line 1298  void MainWindow::on_action_file_open() Line 1320  void MainWindow::on_action_file_open()
1320          }          }
1321          instrument_menu->get_submenu()->items().clear();          instrument_menu->get_submenu()->items().clear();
1322    
1323            m_SampleImportQueue.clear();
1324          m_refTreeModel->clear();          m_refTreeModel->clear();
1325          m_refSamplesTreeModel->clear();          m_refSamplesTreeModel->clear();
1326          if (file) delete file;          if (file) delete file;
# Line 1337  void MainWindow::on_loader_finished() Line 1360  void MainWindow::on_loader_finished()
1360    
1361  void MainWindow::on_action_file_save()  void MainWindow::on_action_file_save()
1362  {  {
1363        if (!file) return;
1364        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();
1375  }  }
1376    
1377  void MainWindow::on_action_file_save_as()  void MainWindow::on_action_file_save_as()
1378  {  {
1379        if (!file) return;
1380      Gtk::FileChooserDialog dialog(*this, "Open", Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, "Open", Gtk::FILE_CHOOSER_ACTION_SAVE);
1381      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1382      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
# Line 1349  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();
1397        }
1398    }
1399    
1400    // actually write the sample(s)' data to the gig file
1401    void MainWindow::__import_queued_samples() {
1402        std::cout << "Starting sample import\n" << std::flush;
1403        Glib::ustring error_files;
1404        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());
1407            SF_INFO info;
1408            info.format = 0;
1409            SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);
1410            try {
1411                if (!hFile) throw std::string("could not open file");
1412                // determine sample's bit depth
1413                int bitdepth;
1414                switch (info.format & 0xff) {
1415                    case SF_FORMAT_PCM_S8:
1416                        bitdepth = 16; // we simply convert to 16 bit for now
1417                        break;
1418                    case SF_FORMAT_PCM_16:
1419                        bitdepth = 16;
1420                        break;
1421                    case SF_FORMAT_PCM_24:
1422                        bitdepth = 32; // we simply convert to 32 bit for now
1423                        break;
1424                    case SF_FORMAT_PCM_32:
1425                        bitdepth = 32;
1426                        break;
1427                    case SF_FORMAT_PCM_U8:
1428                        bitdepth = 16; // we simply convert to 16 bit for now
1429                        break;
1430                    case SF_FORMAT_FLOAT:
1431                        bitdepth = 32;
1432                        break;
1433                    case SF_FORMAT_DOUBLE:
1434                        bitdepth = 32; // I guess we will always truncate this to 32 bit
1435                        break;
1436                    default:
1437                        sf_close(hFile); // close sound file
1438                        throw std::string("format not supported"); // unsupported subformat (yet?)
1439                }
1440                // allocate appropriate copy buffer (TODO: for now we copy it in one piece, might be tough for very long samples)
1441                // and copy sample data into buffer
1442                int8_t* buffer = NULL;
1443                switch (bitdepth) {
1444                    case 16:
1445                        buffer = new int8_t[2 * info.channels * info.frames];
1446                        sf_readf_short(hFile, (short*) buffer, info.frames); // libsndfile does the conversion for us (if needed)
1447                        break;
1448                    case 32:
1449                        buffer = new int8_t[4 * info.channels * info.frames];
1450                        sf_readf_int(hFile, (int*) buffer, info.frames); // libsndfile does the conversion for us (if needed)
1451                        break;
1452                }
1453                // write from buffer directly (physically) into .gig file
1454                (*iter).gig_sample->Write(buffer, info.frames);
1455                // cleanup
1456                sf_close(hFile);
1457                delete buffer;
1458                // on success we remove the sample from the import queue, otherwise keep it, maybe it works the next time ?
1459                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)
1463                if (error_files.size()) error_files += "\n";
1464                error_files += (*iter).sample_path += " (" + what + ")";
1465                ++iter;
1466            }
1467        }
1468        // show error message box when some sample(s) could not be imported
1469        if (error_files.size()) {
1470            Glib::ustring txt = "Could not import the following sample(s):\n" + error_files;
1471            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1472            msg.run();
1473      }      }
1474  }  }
1475    
# Line 1557  void MainWindow::load_gig(gig::File* gig Line 1677  void MainWindow::load_gig(gig::File* gig
1677      instrument_menu->get_submenu()->show_all_children();      instrument_menu->get_submenu()->show_all_children();
1678    
1679      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1680          Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();          if (group->Name != "") {
1681          Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1682          rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              Gtk::TreeModel::Row rowGroup = *iterGroup;
1683          rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();
1684          rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_group]  = group;
1685          for (gig::Sample* sample = group->GetFirstSample(); sample; sample = group->GetNextSample()) {              rowGroup[m_SamplesModel.m_col_sample] = NULL;
1686              Gtk::TreeModel::iterator iterSample = m_refSamplesTreeModel->append(rowGroup.children());              for (gig::Sample* sample = group->GetFirstSample(); sample; sample = group->GetNextSample()) {
1687              Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::iterator iterSample = m_refSamplesTreeModel->append(rowGroup.children());
1688              rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  Gtk::TreeModel::Row rowSample = *iterSample;
1689              rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();
1690              rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1691                    rowSample[m_SamplesModel.m_col_group]  = NULL;
1692                }
1693          }          }
1694      }      }
1695  }  }
# Line 1639  void MainWindow::on_action_add_group() { Line 1761  void MainWindow::on_action_add_group() {
1761  }  }
1762    
1763  void MainWindow::on_action_add_sample() {  void MainWindow::on_action_add_sample() {
1764      //TODO: open browse for file dialog for adding new samples      if (!file) return;
1765        // get selected group
1766        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
1767        Gtk::TreeModel::iterator it = sel->get_selected();
1768        if (!it) return;
1769        Gtk::TreeModel::Row row = *it;
1770        gig::Group* group = row[m_SamplesModel.m_col_group];
1771        if (!group) { // not a group, but a sample is selected (probably)
1772            gig::Sample* sample = row[m_SamplesModel.m_col_sample];
1773            if (!sample) return;
1774            it = row.parent(); // resolve parent (that is the sample's group)
1775            if (!it) return;
1776            row = *it;
1777            group = row[m_SamplesModel.m_col_group];
1778            if (!group) return;
1779        }
1780        // show 'browse for file' dialog
1781        Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)"));
1782        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1783        dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1784        dialog.set_select_multiple(true);
1785        Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile
1786        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");
1796        Gtk::FileFilter allpassfilter; // matches every file
1797        allpassfilter.add_pattern("*.*");
1798        allpassfilter.set_name("All Files");
1799        dialog.add_filter(soundfilter);
1800        dialog.add_filter(allpassfilter);
1801        if (dialog.run() == Gtk::RESPONSE_OK) {
1802            Glib::ustring error_files;
1803            Glib::SListHandle<Glib::ustring> filenames = dialog.get_filenames();
1804            for (Glib::SListHandle<Glib::ustring>::iterator iter = filenames.begin(); iter != filenames.end(); ++iter) {
1805                printf("Adding sample %s\n",(*iter).c_str());
1806                // use libsndfile to retrieve file informations
1807                SF_INFO info;
1808                info.format = 0;
1809                SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);
1810                try {
1811                    if (!hFile) throw std::string("could not open file");
1812                    int bitdepth;
1813                    switch (info.format & 0xff) {
1814                        case SF_FORMAT_PCM_S8:
1815                            bitdepth = 16; // we simply convert to 16 bit for now
1816                            break;
1817                        case SF_FORMAT_PCM_16:
1818                            bitdepth = 16;
1819                            break;
1820                        case SF_FORMAT_PCM_24:
1821                            bitdepth = 32; // we simply convert to 32 bit for now
1822                            break;
1823                        case SF_FORMAT_PCM_32:
1824                            bitdepth = 32;
1825                            break;
1826                        case SF_FORMAT_PCM_U8:
1827                            bitdepth = 16; // we simply convert to 16 bit for now
1828                            break;
1829                        case SF_FORMAT_FLOAT:
1830                            bitdepth = 32;
1831                            break;
1832                        case SF_FORMAT_DOUBLE:
1833                            bitdepth = 32; // I guess we will always truncate this to 32 bit
1834                            break;
1835                        default:
1836                            sf_close(hFile); // close sound file
1837                            throw std::string("format not supported"); // unsupported subformat (yet?)
1838                    }
1839                    // add a new sample to the .gig file
1840                    gig::Sample* sample = file->AddSample();
1841                    sample->pInfo->Name = (*iter).substr((*iter).rfind('/') + 1).raw(); // file name without path
1842                    sample->Channels = info.channels;
1843                    sample->BitDepth = bitdepth;
1844                    sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
1845                    sample->SamplesPerSecond = info.samplerate;
1846                    // schedule resizing the sample (which will be done physically when File::Save() is called)
1847                    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
1851                    SampleImportItem sched_item;
1852                    sched_item.gig_sample  = sample;
1853                    sched_item.sample_path = *iter;
1854                    m_SampleImportQueue.push_back(sched_item);
1855                    // add sample to the tree view
1856                    Gtk::TreeModel::iterator iterSample = m_refSamplesTreeModel->append(row.children());
1857                    Gtk::TreeModel::Row rowSample = *iterSample;
1858                    rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();
1859                    rowSample[m_SamplesModel.m_col_sample] = sample;
1860                    rowSample[m_SamplesModel.m_col_group]  = NULL;
1861                    // close sound file
1862                    sf_close(hFile);
1863                } catch (std::string what) { // remember the files that made trouble (and their cause)
1864                    if (error_files.size()) error_files += "\n";
1865                    error_files += *iter += " (" + what + ")";
1866                }
1867            }
1868            // show error message box when some file(s) could not be opened / added
1869            if (error_files.size()) {
1870                Glib::ustring txt = "Could not add the following sample(s):\n" + error_files;
1871                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1872                msg.run();
1873            }
1874        }
1875  }  }
1876    
1877  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
1878      //TODO: remove the selected group or sample      if (!file) return;
1879        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
1880        Gtk::TreeModel::iterator it = sel->get_selected();
1881        if (it) {
1882            Gtk::TreeModel::Row row = *it;
1883            gig::Group* group   = row[m_SamplesModel.m_col_group];
1884            gig::Sample* sample = row[m_SamplesModel.m_col_sample];
1885            Glib::ustring name  = row[m_SamplesModel.m_col_name];
1886            try {
1887                // remove group or sample from the gig file
1888                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);
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) {
1907                    // remove sample from the .gig file
1908                    file->DeleteSample(sample);
1909                    // if sample was just previously added, remove it from the import queue
1910                    for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); iter != m_SampleImportQueue.end(); ++iter) {
1911                        if ((*iter).gig_sample == sample) {
1912                            printf("Removing previously added sample '%s'\n", (*iter).sample_path.c_str());
1913                            m_SampleImportQueue.erase(iter);
1914                            break;
1915                        }
1916                    }
1917                }
1918                // remove respective row(s) from samples tree view
1919                m_refSamplesTreeModel->erase(it);
1920            } catch (RIFF::Exception e) {
1921                Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1922                msg.run();
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.1082  
changed lines
  Added in v.1096

  ViewVC Help
Powered by ViewVC