From: Colin Fletcher Date: Fri, 5 Apr 2013 16:48:36 +0000 (+0100) Subject: Fix display of Spectral Analysis when no tracks are selected. X-Git-Tag: 3.1~12^2 X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;h=6c7a61f6e5aeb1fc0c8114eb22c24629dfce2bad;hp=fcf7530676f840e4444213a27afb53255010d0d8;p=ardour.git Fix display of Spectral Analysis when no tracks are selected. Spectral Analysis now displays graphs for selected regions, even when there are no tracks selected. Fixes #2226. --- diff --git a/gtk2_ardour/analysis_window.cc b/gtk2_ardour/analysis_window.cc index e93fad887c..998ab8ab12 100644 --- a/gtk2_ardour/analysis_window.cc +++ b/gtk2_ardour/analysis_window.cc @@ -235,7 +235,7 @@ AnalysisWindow::analyze() } void -AnalysisWindow::analyze_data (Gtk::Button */*button*/) +AnalysisWindow::analyze_data (Gtk::Button * /*button*/) { track_list_ready = false; { @@ -251,29 +251,29 @@ AnalysisWindow::analyze_data (Gtk::Button */*button*/) float *gain = (float *) malloc(sizeof(float) * 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) { - boost::shared_ptr pl - = boost::dynamic_pointer_cast((*i)->playlist()); - if (!pl) - continue; + // if timeSelection + if (source_selection_ranges_rb.get_active()) { + TimeSelection ts = s.time; - RouteUI *rui = dynamic_cast(*i); - int n_inputs = rui->route()->n_inputs().n_audio(); // FFT is audio only + for (TrackSelection::iterator i = s.tracks.begin(); i != s.tracks.end(); ++i) { + boost::shared_ptr pl + = boost::dynamic_pointer_cast((*i)->playlist()); - // Busses don't have playlists, so we need to check that we actually are working with a playlist - if (!pl || !rui) - continue; + if (!pl) + continue; - FFTResult *res = fft_graph.prepareResult(rui->color(), rui->route()->name()); + RouteUI *rui = dynamic_cast(*i); + int n_inputs = rui->route()->n_inputs().n_audio(); // FFT is audio only - // if timeSelection - if (source_selection_ranges_rb.get_active()) { -// cerr << "Analyzing ranges on track " << *&rui->route().name() << endl; + // Busses don't have playlists, so we need to check that we actually are working with a playlist + if (!pl || !rui) + continue; + // std::cerr << "Analyzing ranges on track " << rui->route()->name() << std::endl; + + FFTResult *res = fft_graph.prepareResult(rui->color(), rui->route()->name()); for (std::list::iterator j = ts.begin(); j != ts.end(); ++j) { int n; @@ -303,67 +303,72 @@ AnalysisWindow::analyze_data (Gtk::Button */*button*/) } } } - } else if (source_selection_regions_rb.get_active()) { -// cerr << "Analyzing selected regions on track " << *&rui->route().name() << endl; - - TimeAxisView *current_axis = (*i); - - 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) - continue; - - // Check that the region really is selected on _this_ track/solo - if ( &arv->get_time_axis_view() != current_axis) - continue; - -// cerr << " - " << (*j)->region().name() << ": " << (*j)->region().length() << " samples starting at " << (*j)->region().position() << endl; - int n; - for (int channel = 0; channel < n_inputs; channel++) { - - framecnt_t x = 0; + res->finalize(); + + Gtk::TreeModel::Row newrow = *(tlmodel)->append(); + newrow[tlcols.trackname] = rui->route()->name(); + newrow[tlcols.visible] = true; + newrow[tlcols.color] = rui->color(); + newrow[tlcols.graph] = res; + } + } else if (source_selection_regions_rb.get_active()) { + RegionSelection ars = s.regions; + // std::cerr << "Analyzing selected regions" << std::endl; + + 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) + continue; + + // std::cerr << " - " << (*j)->region().name() << ": " << (*j)->region().length() << " samples starting at " << (*j)->region().position() << std::endl; + RouteTimeAxisView *rtav = dynamic_cast(&arv->get_time_axis_view()); + if (!rtav) { + /* shouldn't happen... */ + continue; + } + FFTResult *res = fft_graph.prepareResult(rtav->color(), arv->get_item_name()); + int n; + for (unsigned int channel = 0; channel < arv->region()->n_channels(); channel++) { - framecnt_t length = arv->region()->length(); + framecnt_t x = 0; + framecnt_t length = arv->region()->length(); - while (x < length) { - // TODO: What about stereo+ channels? composite all to one, I guess + 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 = fft_graph.windowSize(); + if (x + n >= length ) { + n = length - x; + } - memset (buf, 0, n * sizeof (Sample)); - n = arv->audio_region()->read_at(buf, mixbuf, gain, arv->region()->position() + x, n, channel); + memset (buf, 0, n * sizeof (Sample)); + n = arv->audio_region()->read_at(buf, mixbuf, gain, arv->region()->position() + x, n, channel); - if (n == 0) - break; + if (n == 0) + break; - if ( n < fft_graph.windowSize()) { - for (int j = n; j < fft_graph.windowSize(); j++) { - buf[j] = 0.0; - } + if ( n < fft_graph.windowSize()) { + for (int j = n; j < fft_graph.windowSize(); j++) { + buf[j] = 0.0; } - - res->analyzeWindow(buf); - - x += n; } - } -// cerr << "Found: " << (*j)->get_item_name() << endl; + res->analyzeWindow(buf); + x += n; + } } + // std::cerr << "Found: " << (*j)->get_item_name() << std::endl; + res->finalize(); - } - res->finalize(); + Gtk::TreeModel::Row newrow = *(tlmodel)->append(); + newrow[tlcols.trackname] = arv->get_item_name(); + newrow[tlcols.visible] = true; + newrow[tlcols.color] = rtav->color(); + newrow[tlcols.graph] = res; + } - Gtk::TreeModel::Row newrow = *(tlmodel)->append(); - newrow[tlcols.trackname] = rui->route()->name(); - newrow[tlcols.visible] = true; - newrow[tlcols.color] = rui->color(); - newrow[tlcols.graph] = res; }