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

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

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

revision 1661 by schoenebeck, Sun Feb 3 14:10:47 2008 UTC revision 1673 by schoenebeck, Wed Feb 6 22:08:29 2008 UTC
# Line 208  MainWindow::MainWindow() : Line 208  MainWindow::MainWindow() :
208          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
209          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
210      );      );
211        actionGroup->add(
212            Gtk::Action::create("ReplaceAllSamplesInAllGroups", _("Replace All Samples In All Groups")),
213            sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
214        );
215    
216      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
217      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
# Line 248  MainWindow::MainWindow() : Line 252  MainWindow::MainWindow() :
252          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
253          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
254          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
255            "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
256          "    <separator/>"          "    <separator/>"
257          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
258          "  </popup>"          "  </popup>"
# Line 1490  void MainWindow::on_action_add_sample() Line 1495  void MainWindow::on_action_add_sample()
1495              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1496              msg.run();              msg.run();
1497          }          }
1498        }
1499    }
1500    
1501    void MainWindow::on_action_replace_all_samples_in_all_groups()
1502    {
1503        if (!file) return;
1504        Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
1505                                      Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
1506        Gtk::Label description(
1507            _("This is a very specific function. It tries to replace all samples "
1508              "in the current gig file by samples located in the directory chosen "
1509              "by you above.\n\n"
1510              "It works like this: For each sample in the gig file it tries to "
1511              "find a sample file in the selected directory with the same name as "
1512              "the sample in the gig file. Optionally you can add a filename "
1513              "postfix below, which will be added to the filename expected to be "
1514              "found. That is, assume you have a gig file with a sample called "
1515              "'Snare', if you enter '.wav' below (like it's done by default), it "
1516              "assumes to find a sample file called 'Snare.wav' and will replace "
1517              "the sample in the gig file accordingly. If you don't need such a "
1518              "postfix, blank the field below. Any gig sample where no "
1519              "appropriate sample file could be found, will be reported and left "
1520              "untouched.\n\n")
1521        );
1522        description.set_line_wrap(true);
1523        Gtk::HBox entryArea;
1524        Gtk::Label entryLabel( _("Add Filename Extension: "), Gtk::ALIGN_RIGHT);
1525        Gtk::Entry postfixEntryBox;
1526        postfixEntryBox.set_text(".wav");
1527        entryArea.pack_start(entryLabel);
1528        entryArea.pack_start(postfixEntryBox);
1529        dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);
1530        dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
1531        description.show();
1532        entryLabel.show();
1533        postfixEntryBox.show();
1534        entryArea.show();
1535        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1536        dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
1537        dialog.set_select_multiple(false);
1538        // fix label width (because Gtk by design doesn't
1539        // know anything about the parent's size)
1540    #if 0 //FIXME: doesn't work
1541        int dialogW, dialogH, labelW, labelH;
1542        dialog.get_size_request(dialogW, dialogH);
1543        description.get_size_request(labelW, labelH);
1544        std::cout << "dialog(" << dialogW << "," << dialogH << ")\nlabel(" << labelW << "," << labelH << ")\n" << std::flush;
1545        description.set_size_request(dialogW, labelH);
1546    #endif
1547        if (dialog.run() == Gtk::RESPONSE_OK)
1548        {
1549            Glib::ustring error_files;
1550            Glib::ustring folder = dialog.get_filename();
1551            for (gig::Sample* sample = file->GetFirstSample();
1552                 sample; sample = file->GetNextSample())
1553            {
1554                std::string filename =
1555                    folder + G_DIR_SEPARATOR_S + sample->pInfo->Name +
1556                    postfixEntryBox.get_text().raw();
1557                SF_INFO info;
1558                info.format = 0;
1559                SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
1560                try
1561                {
1562                    if (!hFile) throw std::string("could not open file");
1563                    int bitdepth;
1564                    switch (info.format & 0xff) {
1565                        case SF_FORMAT_PCM_S8:
1566                        case SF_FORMAT_PCM_16:
1567                        case SF_FORMAT_PCM_U8:
1568                            bitdepth = 16;
1569                            break;
1570                        case SF_FORMAT_PCM_24:
1571                        case SF_FORMAT_PCM_32:
1572                        case SF_FORMAT_FLOAT:
1573                        case SF_FORMAT_DOUBLE:
1574                            bitdepth = 24;
1575                            break;
1576                        default:
1577                            sf_close(hFile);
1578                            throw std::string("format not supported");
1579                    }
1580                    SampleImportItem sched_item;
1581                    sched_item.gig_sample  = sample;
1582                    sched_item.sample_path = filename;
1583                    m_SampleImportQueue.push_back(sched_item);
1584                    sf_close(hFile);
1585                    file_changed();
1586                }
1587                catch (std::string what)
1588                {
1589                    if (error_files.size()) error_files += "\n";
1590                        error_files += filename += " (" + what + ")";
1591                }
1592            }
1593            // show error message box when some file(s) could not be opened / added
1594            if (error_files.size()) {
1595                Glib::ustring txt =
1596                    _("Could not replace the following sample(s):\n") + error_files;
1597                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1598                msg.run();
1599            }
1600      }      }
1601  }  }
1602    

Legend:
Removed from v.1661  
changed lines
  Added in v.1673

  ViewVC Help
Powered by ViewVC