/[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

gigedit/branches/linuxsampler_org/src/mainwindow.cpp revision 1052 by persson, Sat Mar 3 12:20:01 2007 UTC gigedit/trunk/src/mainwindow.cpp revision 1087 by schoenebeck, Fri Mar 9 19:45:45 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  #endif  #endif
32    
33    #include <stdio.h>
34    #include <sndfile.h>
35    
36  #define _(String) gettext(String)  #define _(String) gettext(String)
37    
38    template<class T> inline std::string ToString(T o) {
39        std::stringstream ss;
40        ss << o;
41        return ss.str();
42    }
43    
44  bool update_gui;  bool update_gui;
45    
# Line 524  MainWindow::MainWindow() : Line 533  MainWindow::MainWindow() :
533      m_TreeView.signal_button_press_event().connect_notify(      m_TreeView.signal_button_press_event().connect_notify(
534          sigc::mem_fun(*this, &MainWindow::on_button_release));          sigc::mem_fun(*this, &MainWindow::on_button_release));
535    
536      // Add the TreeView, inside a ScrolledWindow, with the button underneath:      // Add the TreeView tab, inside a ScrolledWindow, with the button underneath:
537      m_ScrolledWindow.add(m_TreeView);      m_ScrolledWindow.add(m_TreeViewNotebook);
538      m_ScrolledWindow.set_size_request(400, 600);      m_ScrolledWindow.set_size_request(400, 600);
539      m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
540    
# Line 784  MainWindow::MainWindow() : Line 793  MainWindow::MainWindow() :
793      m_HPaned.add2(m_Notebook);      m_HPaned.add2(m_Notebook);
794    
795    
796        m_TreeViewNotebook.append_page(m_TreeViewSamples, "Samples");
797        m_TreeViewNotebook.append_page(m_TreeView, "Instruments");
798    
799    
800      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
801    
802      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
# Line 817  MainWindow::MainWindow() : Line 830  MainWindow::MainWindow() :
830      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
831                       sigc::mem_fun(                       sigc::mem_fun(
832                           *this, &MainWindow::hide));                           *this, &MainWindow::hide));
833        actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));
834    
835      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
836      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("MenuHelp",
837                                           action->property_label()));                                           action->property_label()));
# Line 825  MainWindow::MainWindow() : Line 840  MainWindow::MainWindow() :
840                       sigc::mem_fun(                       sigc::mem_fun(
841                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
842  #endif  #endif
843      action = Gtk::Action::create("Remove", "Ta bort");      action = Gtk::Action::create("Remove", Gtk::Stock::REMOVE);
844      actionGroup->add(action,      actionGroup->add(action,
845                       sigc::mem_fun(                       sigc::mem_fun(
846                           *this, &MainWindow::hide));                           *this, &MainWindow::hide));
847    
848        // sample right-click popup actions
849        actionGroup->add(
850            Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
851            sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
852        );
853        actionGroup->add(
854            Gtk::Action::create("AddGroup", _("Add _Group")),
855            sigc::mem_fun(*this, &MainWindow::on_action_add_group)
856        );
857        actionGroup->add(
858            Gtk::Action::create("AddSample", _("Add _Sample(s)")),
859            sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
860        );
861        actionGroup->add(
862            Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
863            sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
864        );
865    
866      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
867      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
868      // add_accel_group(uiManager->get_accel_group());      // add_accel_group(uiManager->get_accel_group());
# Line 848  MainWindow::MainWindow() : Line 881  MainWindow::MainWindow() :
881          "      <separator/>"          "      <separator/>"
882          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
883          "    </menu>"          "    </menu>"
884            "    <menu action='MenuInstrument'>"
885            "    </menu>"
886  #ifdef ABOUT_DIALOG  #ifdef ABOUT_DIALOG
887          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
888          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 858  MainWindow::MainWindow() : Line 893  MainWindow::MainWindow() :
893          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
894          "    <menuitem action='Remove'/>"          "    <menuitem action='Remove'/>"
895          "  </popup>"          "  </popup>"
896            "  <popup name='SamplePopupMenu'>"
897            "    <menuitem action='SampleProperties'/>"
898            "    <menuitem action='AddGroup'/>"
899            "    <menuitem action='AddSample'/>"
900            "    <separator/>"
901            "    <menuitem action='RemoveSample'/>"
902            "  </popup>"
903          "</ui>";          "</ui>";
904      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
905    
# Line 883  MainWindow::MainWindow() : Line 925  MainWindow::MainWindow() :
925      m_TreeView.append_column("Instrument", m_Columns.m_col_name);      m_TreeView.append_column("Instrument", m_Columns.m_col_name);
926      m_TreeView.set_headers_visible(false);      m_TreeView.set_headers_visible(false);
927    
928        // create samples treeview (including its data model)
929        m_refSamplesTreeModel = Gtk::TreeStore::create(m_SamplesModel);
930        m_TreeViewSamples.set_model(m_refSamplesTreeModel);
931        m_TreeViewSamples.append_column("Samples", m_SamplesModel.m_col_name);
932        m_TreeViewSamples.set_headers_visible(false);
933        m_TreeViewSamples.signal_button_press_event().connect_notify(
934            sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
935        );
936    
937      file = 0;      file = 0;
938    
939      show_all_children();      show_all_children();
# Line 1229  LoadDialog::LoadDialog() Line 1280  LoadDialog::LoadDialog()
1280    
1281  void MainWindow::on_action_file_new()  void MainWindow::on_action_file_new()
1282  {  {
1283        m_SampleImportQueue.clear();
1284  }  }
1285    
1286  void MainWindow::on_action_file_open()  void MainWindow::on_action_file_open()
# Line 1242  void MainWindow::on_action_file_open() Line 1294  void MainWindow::on_action_file_open()
1294      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1295          printf("filename=%s\n", dialog.get_filename().c_str());          printf("filename=%s\n", dialog.get_filename().c_str());
1296    
1297            // remove all entries from "Instrument" menu
1298            Gtk::MenuItem* instrument_menu =
1299                dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument"));
1300            instrument_menu->hide();
1301            for (int i = 0; i < instrument_menu->get_submenu()->items().size(); i++) {
1302                delete &instrument_menu->get_submenu()->items()[i];
1303            }
1304            instrument_menu->get_submenu()->items().clear();
1305    
1306            m_SampleImportQueue.clear();
1307          m_refTreeModel->clear();          m_refTreeModel->clear();
1308            m_refSamplesTreeModel->clear();
1309          if (file) delete file;          if (file) delete file;
1310    
1311          // getInfo(dialog.get_filename().c_str(), *this);          // getInfo(dialog.get_filename().c_str(), *this);
# Line 1280  void MainWindow::on_loader_finished() Line 1343  void MainWindow::on_loader_finished()
1343    
1344  void MainWindow::on_action_file_save()  void MainWindow::on_action_file_save()
1345  {  {
1346        if (!file) return;
1347        file->Save();
1348        __import_queued_samples();
1349  }  }
1350    
1351  void MainWindow::on_action_file_save_as()  void MainWindow::on_action_file_save_as()
1352  {  {
1353        if (!file) return;
1354      Gtk::FileChooserDialog dialog(*this, "Open", Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, "Open", Gtk::FILE_CHOOSER_ACTION_SAVE);
1355      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1356      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
# Line 1293  void MainWindow::on_action_file_save_as( Line 1360  void MainWindow::on_action_file_save_as(
1360      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1361          printf("filename=%s\n", dialog.get_filename().c_str());          printf("filename=%s\n", dialog.get_filename().c_str());
1362          file->Save(dialog.get_filename());          file->Save(dialog.get_filename());
1363            __import_queued_samples();
1364        }
1365    }
1366    
1367    // actually write the sample(s)' data to the gig file
1368    void MainWindow::__import_queued_samples() {
1369        Glib::ustring error_files;
1370        for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); iter != m_SampleImportQueue.end(); ++iter) {
1371            printf("Importing sample %s\n",(*iter).sample_path.c_str());
1372            SF_INFO info;
1373            info.format = 0;
1374            SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);
1375            try {
1376                if (!hFile) throw std::string("could not open file");
1377                // determine sample's bit depth
1378                int bitdepth;
1379                switch (info.format & 0xff) {
1380                    case SF_FORMAT_PCM_S8:
1381                        bitdepth = 16; // we simply convert to 16 bit for now
1382                        break;
1383                    case SF_FORMAT_PCM_16:
1384                        bitdepth = 16;
1385                        break;
1386                    case SF_FORMAT_PCM_24:
1387                        bitdepth = 32; // we simply convert to 32 bit for now
1388                        break;
1389                    case SF_FORMAT_PCM_32:
1390                        bitdepth = 32;
1391                        break;
1392                    case SF_FORMAT_PCM_U8:
1393                        bitdepth = 16; // we simply convert to 16 bit for now
1394                        break;
1395                    case SF_FORMAT_FLOAT:
1396                        bitdepth = 32;
1397                        break;
1398                    case SF_FORMAT_DOUBLE:
1399                        bitdepth = 32; // I guess we will always truncate this to 32 bit
1400                        break;
1401                    default:
1402                        sf_close(hFile); // close sound file
1403                        throw std::string("format not supported"); // unsupported subformat (yet?)
1404                }
1405                // allocate appropriate copy buffer (TODO: for now we copy it in one piece, might be tough for very long samples)
1406                // and copy sample data into buffer
1407                int8_t* buffer = NULL;
1408                switch (bitdepth) {
1409                    case 16:
1410                        buffer = new int8_t[2 * info.channels * info.frames];
1411                        sf_readf_short(hFile, (short*) buffer, info.frames); // libsndfile does the conversion for us (if needed)
1412                        break;
1413                    case 32:
1414                        buffer = new int8_t[4 * info.channels * info.frames];
1415                        sf_readf_int(hFile, (int*) buffer, info.frames); // libsndfile does the conversion for us (if needed)
1416                        break;
1417                }
1418                // write from buffer directly (physically) into .gig file
1419                (*iter).gig_sample->Write(buffer, info.frames);
1420                // cleanup
1421                sf_close(hFile);
1422                delete buffer;
1423                // on success we remove the sample from the import queue, otherwise keep it, maybe it works the next time ?
1424                m_SampleImportQueue.erase(iter);
1425            } catch (std::string what) { // remember the files that made trouble (and their cause)
1426                if (error_files.size()) error_files += "\n";
1427                error_files += (*iter).sample_path += " (" + what + ")";
1428            }
1429        }
1430        // show error message box when some sample(s) could not be imported
1431        if (error_files.size()) {
1432            Glib::ustring txt = "Could not import the following sample(s):\n" + error_files;
1433            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1434            msg.run();
1435      }      }
1436  }  }
1437    
# Line 1474  void MainWindow::load_gig(gig::File* gig Line 1613  void MainWindow::load_gig(gig::File* gig
1613    
1614      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1615    
1616        Gtk::MenuItem* instrument_menu =
1617            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument"));
1618    
1619        int instrument_index = 0;
1620        Gtk::RadioMenuItem::Group instrument_group;
1621      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1622           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1623          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1624          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1625          row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();          row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();
1626          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1627            // create a menu item for this instrument
1628            Gtk::RadioMenuItem* item= new Gtk::RadioMenuItem(instrument_group, instrument->pInfo->Name.c_str());
1629            instrument_menu->get_submenu()->append(*item);
1630            item->signal_activate().connect(
1631                sigc::bind(
1632                    sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
1633                    instrument_index
1634                )
1635            );
1636            instrument_index++;
1637        }
1638        instrument_menu->show();
1639        instrument_menu->get_submenu()->show_all_children();
1640    
1641        for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1642            Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1643            Gtk::TreeModel::Row rowGroup = *iterGroup;
1644            rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();
1645            rowGroup[m_SamplesModel.m_col_group]  = group;
1646            rowGroup[m_SamplesModel.m_col_sample] = NULL;
1647            for (gig::Sample* sample = group->GetFirstSample(); sample; sample = group->GetNextSample()) {
1648                Gtk::TreeModel::iterator iterSample = m_refSamplesTreeModel->append(rowGroup.children());
1649                Gtk::TreeModel::Row rowSample = *iterSample;
1650                rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();
1651                rowSample[m_SamplesModel.m_col_sample] = sample;
1652                rowSample[m_SamplesModel.m_col_group]  = NULL;
1653            }
1654      }      }
1655  }  }
1656    
# Line 1502  void MainWindow::on_button_release(GdkEv Line 1673  void MainWindow::on_button_release(GdkEv
1673          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1674      }      }
1675  }  }
1676    
1677    void MainWindow::on_instrument_selection_change(int index) {
1678        m_RegionChooser.set_instrument(file->GetInstrument(index));
1679    }
1680    
1681    void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
1682        if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1683            Gtk::Menu* sample_popup =
1684                dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
1685            // update enabled/disabled state of sample popup items
1686            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
1687            Gtk::TreeModel::iterator it = sel->get_selected();
1688            bool group_selected  = false;
1689            bool sample_selected = false;
1690            if (it) {
1691                Gtk::TreeModel::Row row = *it;
1692                group_selected  = row[m_SamplesModel.m_col_group];
1693                sample_selected = row[m_SamplesModel.m_col_sample];
1694            }
1695            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->set_sensitive(group_selected || sample_selected);
1696            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->set_sensitive(group_selected || sample_selected);
1697            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->set_sensitive(file);
1698            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->set_sensitive(group_selected || sample_selected);
1699            // show sample popup
1700            sample_popup->popup(button->button, button->time);
1701        }
1702    }
1703    
1704    void MainWindow::on_action_sample_properties() {
1705         //TODO: show a dialog where the selected sample's properties can be edited
1706    }
1707    
1708    void MainWindow::on_action_add_group() {
1709        static int __sample_indexer = 0;
1710        if (!file) return;
1711        gig::Group* group = file->AddGroup();
1712        group->Name = "Unnamed Group";
1713        if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
1714        __sample_indexer++;
1715        // update sample tree view
1716        Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1717        Gtk::TreeModel::Row rowGroup = *iterGroup;
1718        rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();
1719        rowGroup[m_SamplesModel.m_col_sample] = NULL;
1720        rowGroup[m_SamplesModel.m_col_group] = group;
1721    }
1722    
1723    void MainWindow::on_action_add_sample() {
1724        if (!file) return;
1725        // get selected group
1726        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
1727        Gtk::TreeModel::iterator it = sel->get_selected();
1728        if (!it) return;
1729        Gtk::TreeModel::Row row = *it;
1730        gig::Group* group = row[m_SamplesModel.m_col_group];
1731        if (!group) { // not a group, but a sample is selected (probably)
1732            gig::Sample* sample = row[m_SamplesModel.m_col_sample];
1733            if (!sample) return;
1734            it = row.parent(); // resolve parent (that is the sample's group)
1735            if (!it) return;
1736            row = *it;
1737            group = row[m_SamplesModel.m_col_group];
1738            if (!group) return;
1739        }
1740        // show 'browse for file' dialog
1741        Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)"));
1742        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1743        dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1744        dialog.set_select_multiple(true);
1745        Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile (yet to do ;-)
1746        soundfilter.add_pattern("*.wav");
1747        soundfilter.set_name("Sound Files");
1748        Gtk::FileFilter allpassfilter; // matches every file
1749        allpassfilter.add_pattern("*.*");
1750        allpassfilter.set_name("All Files");
1751        dialog.add_filter(soundfilter);
1752        dialog.add_filter(allpassfilter);
1753        if (dialog.run() == Gtk::RESPONSE_OK) {
1754            Glib::ustring error_files;
1755            Glib::SListHandle<Glib::ustring> filenames = dialog.get_filenames();
1756            for (Glib::SListHandle<Glib::ustring>::iterator iter = filenames.begin(); iter != filenames.end(); ++iter) {
1757                printf("Adding sample %s\n",(*iter).c_str());
1758                // use libsndfile to retrieve file informations
1759                SF_INFO info;
1760                info.format = 0;
1761                SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);
1762                try {
1763                    if (!hFile) throw std::string("could not open file");
1764                    int bitdepth;
1765                    switch (info.format & 0xff) {
1766                        case SF_FORMAT_PCM_S8:
1767                            bitdepth = 16; // we simply convert to 16 bit for now
1768                            break;
1769                        case SF_FORMAT_PCM_16:
1770                            bitdepth = 16;
1771                            break;
1772                        case SF_FORMAT_PCM_24:
1773                            bitdepth = 32; // we simply convert to 32 bit for now
1774                            break;
1775                        case SF_FORMAT_PCM_32:
1776                            bitdepth = 32;
1777                            break;
1778                        case SF_FORMAT_PCM_U8:
1779                            bitdepth = 16; // we simply convert to 16 bit for now
1780                            break;
1781                        case SF_FORMAT_FLOAT:
1782                            bitdepth = 32;
1783                            break;
1784                        case SF_FORMAT_DOUBLE:
1785                            bitdepth = 32; // I guess we will always truncate this to 32 bit
1786                            break;
1787                        default:
1788                            sf_close(hFile); // close sound file
1789                            throw std::string("format not supported"); // unsupported subformat (yet?)
1790                    }
1791                    // add a new sample to the .gig file
1792                    gig::Sample* sample = file->AddSample();
1793                    sample->pInfo->Name = (*iter).substr((*iter).rfind('/') + 1).raw(); // file name without path
1794                    sample->Channels = info.channels;
1795                    sample->BitDepth = bitdepth;
1796                    sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
1797                    sample->SamplesPerSecond = info.samplerate;
1798                    // schedule resizing the sample (which will be done physically when File::Save() is called)
1799                    sample->Resize(info.frames);
1800                    // schedule that physical resize and sample import (data copying), performed when "Save" is requested
1801                    SampleImportItem sched_item;
1802                    sched_item.gig_sample  = sample;
1803                    sched_item.sample_path = *iter;
1804                    m_SampleImportQueue.push_back(sched_item);
1805                    // add sample to the tree view
1806                    Gtk::TreeModel::iterator iterSample = m_refSamplesTreeModel->append(row.children());
1807                    Gtk::TreeModel::Row rowSample = *iterSample;
1808                    rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();
1809                    rowSample[m_SamplesModel.m_col_sample] = sample;
1810                    rowSample[m_SamplesModel.m_col_group]  = NULL;
1811                    // close sound file
1812                    sf_close(hFile);
1813                } catch (std::string what) { // remember the files that made trouble (and their cause)
1814                    if (error_files.size()) error_files += "\n";
1815                    error_files += *iter += " (" + what + ")";
1816                }
1817            }
1818            // show error message box when some file(s) could not be opened / added
1819            if (error_files.size()) {
1820                Glib::ustring txt = "Could not add the following sample(s):\n" + error_files;
1821                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1822                msg.run();
1823            }
1824        }
1825    }
1826    
1827    void MainWindow::on_action_remove_sample() {
1828        if (!file) return;
1829        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
1830        Gtk::TreeModel::iterator it = sel->get_selected();
1831        if (it) {
1832            Gtk::TreeModel::Row row = *it;
1833            gig::Group* group   = row[m_SamplesModel.m_col_group];
1834            gig::Sample* sample = row[m_SamplesModel.m_col_sample];
1835            try {
1836                // remove group or sample from the gig file
1837                if (group) {
1838                    file->DeleteGroup(group);
1839                } else if (sample) {
1840                    file->DeleteSample(sample);
1841                }
1842                // if sample was just previously added, remove it from the import queue
1843                if (sample) {
1844                    for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); iter != m_SampleImportQueue.end(); ++iter) {
1845                        if ((*iter).gig_sample == sample) {
1846                            m_SampleImportQueue.erase(iter);
1847                            break;
1848                        }
1849                    }
1850                }
1851                // remove respective row(s) from samples tree view
1852                m_refSamplesTreeModel->erase(it);
1853            } catch (RIFF::Exception e) {
1854                Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1855                msg.run();
1856            }
1857        }
1858    }

Legend:
Removed from v.1052  
changed lines
  Added in v.1087

  ViewVC Help
Powered by ViewVC