X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fanalysis_window.cc;h=ed2b90b34fa29ebeec165df8dfb613b7c3ca01bf;hb=6001b8d28dd764bada8b9198a5f91e0a2f5251f6;hp=f742afd7274a9a66ee901236919c3962e75d198c;hpb=6f4a92f740b2fd75794489ce58f9348f8adf6bf4;p=ardour.git diff --git a/gtk2_ardour/analysis_window.cc b/gtk2_ardour/analysis_window.cc index f742afd727..ed2b90b34f 100644 --- a/gtk2_ardour/analysis_window.cc +++ b/gtk2_ardour/analysis_window.cc @@ -16,7 +16,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #include @@ -25,9 +24,9 @@ #include #include -#include -#include -#include +#include "ardour/audioregion.h" +#include "ardour/audioplaylist.h" +#include "ardour/types.h" #include "analysis_window.h" @@ -42,9 +41,8 @@ using namespace ARDOUR; using namespace PBD; -AnalysisWindow::AnalysisWindow() - : ArdourDialog(_("analysis window")), - +AnalysisWindow::AnalysisWindow() : + source_selection_label (_("Signal source")), source_selection_ranges_rb (_("Selected ranges")), source_selection_regions_rb (_("Selected regions")), @@ -52,16 +50,22 @@ AnalysisWindow::AnalysisWindow() display_model_label (_("Display model")), display_model_composite_separate_rb (_("Composite graphs for each track")), display_model_composite_all_tracks_rb (_("Composite graph of all tracks")), + + show_minmax_button (_("Show frequency power range")), + show_normalized_button (_("Normalize values")), - fft_graph (2048) + fft_graph (16384) { + set_name(_("FFT analysis window")); + set_title(_("FFT analysis window")); + track_list_ready = false; // Left side: track list + controls tlmodel = Gtk::ListStore::create(tlcols); track_list.set_model (tlmodel); track_list.append_column(_("Track"), tlcols.trackname); - track_list.append_column_editable(_("Visible"), tlcols.visible); + track_list.append_column_editable(_("Show"), tlcols.visible); track_list.set_headers_visible(true); track_list.set_reorderable(false); track_list.get_selection()->set_mode (Gtk::SELECTION_NONE); @@ -125,17 +129,31 @@ AnalysisWindow::AnalysisWindow() bind ( mem_fun(*this, &AnalysisWindow::display_model_changed), &display_model_composite_all_tracks_rb)); } - vbox.pack_start(hseparator2, false, false); + // Analyze button refresh_button.set_name("EditorGTKButton"); - refresh_button.set_label(_("Analyze data")); + refresh_button.set_label(_("Re-analyze data")); refresh_button.signal_clicked().connect ( bind ( mem_fun(*this, &AnalysisWindow::analyze_data), &refresh_button)); vbox.pack_start(refresh_button, false, false, 10); + + + // Feature checkboxes + + // minmax + show_minmax_button.signal_toggled().connect( mem_fun(*this, &AnalysisWindow::show_minmax_changed)); + vbox.pack_start(show_minmax_button, false, false); + + // normalize + show_normalized_button.signal_toggled().connect( mem_fun(*this, &AnalysisWindow::show_normalized_changed)); + vbox.pack_start(show_normalized_button, false, false); + + + - hbox.pack_start(vbox); + hbox.pack_start(vbox, Gtk::PACK_SHRINK); // Analysis window on the right fft_graph.ensure_style(); @@ -145,11 +163,9 @@ AnalysisWindow::AnalysisWindow() // And last we pack the hbox - get_vbox()->pack_start(hbox); - + add(hbox); + show_all(); track_list.show_all(); - - get_vbox()->show_all(); } AnalysisWindow::~AnalysisWindow() @@ -157,6 +173,18 @@ AnalysisWindow::~AnalysisWindow() } +void +AnalysisWindow::show_minmax_changed() +{ + fft_graph.set_show_minmax(show_minmax_button.get_active()); +} + +void +AnalysisWindow::show_normalized_changed() +{ + fft_graph.set_show_normalized(show_normalized_button.get_active()); +} + void AnalysisWindow::set_rangemode() { @@ -221,22 +249,21 @@ AnalysisWindow::analyze_data (Gtk::Button *button) Sample *buf = (Sample *) malloc(sizeof(Sample) * fft_graph.windowSize()); Sample *mixbuf = (Sample *) malloc(sizeof(Sample) * fft_graph.windowSize()); float *gain = (float *) malloc(sizeof(float) * fft_graph.windowSize()); - char *work = (char *) malloc(sizeof(char) * fft_graph.windowSize()); Selection s = PublicEditor::instance().get_selection(); TimeSelection ts = s.time; RegionSelection ars = s.regions; - for (TrackSelection::iterator i = s.tracks.begin(); i != s.tracks.end(); ++i) { - ARDOUR::AudioPlaylist *pl - = dynamic_cast((*i)->playlist()); + boost::shared_ptr pl + = boost::dynamic_pointer_cast((*i)->playlist()); if (!pl) continue; RouteUI *rui = dynamic_cast(*i); - + int n_inputs = rui->route()->n_inputs().n_audio(); // FFT is audio only + // Busses don't have playlists, so we need to check that we actually are working with a playlist if (!pl || !rui) continue; @@ -247,31 +274,33 @@ AnalysisWindow::analyze_data (Gtk::Button *button) if (source_selection_ranges_rb.get_active()) { // cerr << "Analyzing ranges on track " << *&rui->route().name() << endl; - for (std::list::iterator j = ts.begin(); j != ts.end(); ++j) { + for (std::list::iterator j = ts.begin(); j != ts.end(); ++j) { - jack_nframes_t i = 0; int n; - - while ( i < (*j).length() ) { - // TODO: What about stereo+ channels? composite all to one, I guess + for (int channel = 0; channel < n_inputs; channel++) { + nframes_t x = 0; - n = fft_graph.windowSize(); + while ( x < (*j).length() ) { + // TODO: What about stereo+ channels? composite all to one, I guess - if (i + n >= (*j).length() ) { - n = (*j).length() - i; - } - - n = pl->read(buf, mixbuf, gain, work, (*j).start + i, n); - - if ( n < fft_graph.windowSize()) { - for (int j = n; j < fft_graph.windowSize(); j++) { - buf[j] = 0.0; + n = fft_graph.windowSize(); + + if (x + n >= (*j).length() ) { + n = (*j).length() - x; } + + n = pl->read(buf, mixbuf, gain, (*j).start + x, n, channel); + + if ( n < fft_graph.windowSize()) { + for (int j = n; j < fft_graph.windowSize(); j++) { + buf[j] = 0.0; + } + } + + res->analyzeWindow(buf); + + x += n; } - - res->analyzeWindow(buf); - - i += n; } } } else if (source_selection_regions_rb.get_active()) { @@ -279,7 +308,7 @@ AnalysisWindow::analyze_data (Gtk::Button *button) TimeAxisView *current_axis = (*i); - for (std::set::iterator j = ars.begin(); j != ars.end(); ++j) { + for (RegionSelection::iterator j = ars.begin(); j != ars.end(); ++j) { // Check that the region is actually audio (so we can analyze it) AudioRegionView* arv = dynamic_cast(*j); if (!arv) @@ -290,28 +319,36 @@ AnalysisWindow::analyze_data (Gtk::Button *button) continue; // cerr << " - " << (*j)->region().name() << ": " << (*j)->region().length() << " samples starting at " << (*j)->region().position() << endl; - jack_nframes_t i = 0; int n; + for (int channel = 0; channel < n_inputs; channel++) { - while ( i < arv->region().length() ) { - // TODO: What about stereo+ channels? composite all to one, I guess + nframes_t x = 0; - n = fft_graph.windowSize(); - if (i + n >= arv->region().length() ) { - n = arv->region().length() - i; - } + nframes_t length = arv->region()->length(); - n = arv->audio_region().read_at(buf, mixbuf, gain, work, arv->region().position() + i, n); - - if ( n < fft_graph.windowSize()) { - for (int j = n; j < fft_graph.windowSize(); j++) { - buf[j] = 0.0; + while ( x < length ) { + // TODO: What about stereo+ channels? composite all to one, I guess + + n = fft_graph.windowSize(); + if (x + n >= length ) { + n = length - x; } + + n = arv->audio_region()->read_at(buf, mixbuf, gain, arv->region()->position() + x, n, channel); + + if (n == 0) + break; + + if ( n < fft_graph.windowSize()) { + for (int j = n; j < fft_graph.windowSize(); j++) { + buf[j] = 0.0; + } + } + + res->analyzeWindow(buf); + + x += n; } - - res->analyzeWindow(buf); - - i += n; } // cerr << "Found: " << (*j)->get_item_name() << endl; @@ -331,7 +368,6 @@ AnalysisWindow::analyze_data (Gtk::Button *button) free(buf); free(mixbuf); - free(work); track_list_ready = true; } /* end lock */