Mercurial > hg > sonic-visualiser
changeset 73:e200055fe80b
* Add vertical zooming and snap-to-selection for OSC control;
add a demo script
author | Chris Cannam |
---|---|
date | Wed, 15 Nov 2006 18:22:26 +0000 |
parents | 34dc23246f46 |
children | f81611bf11ed |
files | main/MainWindow.cpp main/MainWindow.h osc/demoscript.sh osc/sv-command transform/TransformFactory.cpp transform/TransformFactory.h |
diffstat | 6 files changed, 490 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/main/MainWindow.cpp Tue Nov 14 16:06:00 2006 +0000 +++ b/main/MainWindow.cpp Wed Nov 15 18:22:26 2006 +0000 @@ -151,6 +151,8 @@ this, SLOT(currentLayerChanged(Pane *, Layer *))); connect(m_paneStack, SIGNAL(rightButtonMenuRequested(Pane *, QPoint)), this, SLOT(rightButtonMenuRequested(Pane *, QPoint))); + connect(m_paneStack, SIGNAL(propertyStacksResized()), + this, SLOT(propertyStacksResized())); m_overview = new Overview(frame); m_overview->setViewManager(m_viewManager); @@ -2986,6 +2988,10 @@ m_paneStack->setCurrentPane(pane); m_paneStack->setCurrentLayer(pane, newLayer); + std::cerr << "MainWindow::addPane: global centre frame is " + << m_viewManager->getGlobalCentreFrame() << std::endl; + pane->setCentreFrame(m_viewManager->getGlobalCentreFrame()); + CommandHistory::getInstance()->endCompoundOperation(); updateMenuStates(); @@ -3451,6 +3457,19 @@ } void +MainWindow::propertyStacksResized() +{ +/* + std::cerr << "MainWindow::propertyStacksResized" << std::endl; + Pane *pane = m_paneStack->getCurrentPane(); + if (pane && m_overview) { + std::cerr << "Fixed width: " << pane->width() << std::endl; + m_overview->setFixedWidth(pane->width()); + } +*/ +} + +void MainWindow::showLayerTree() { QTreeView *view = new QTreeView(); @@ -3636,8 +3655,8 @@ if (getMainModel()) { - unsigned long f0 = getMainModel()->getStartFrame(); - unsigned long f1 = getMainModel()->getEndFrame(); + int f0 = getMainModel()->getStartFrame(); + int f1 = getMainModel()->getEndFrame(); bool done = false; @@ -3653,6 +3672,17 @@ f0 = lrint(t0 * getMainModel()->getSampleRate()); f1 = lrint(t1 * getMainModel()->getSampleRate()); + + Pane *pane = m_paneStack->getCurrentPane(); + Layer *layer = 0; + if (pane) layer = pane->getSelectedLayer(); + if (layer) { + size_t resolution; + layer->snapToFeatureFrame(pane, f0, resolution, + Layer::SnapLeft); + layer->snapToFeatureFrame(pane, f1, resolution, + Layer::SnapRight); + } } else if (message.getArgCount() == 1 && message.getArg(0).canConvert(QVariant::String)) { @@ -3843,6 +3873,40 @@ } } + } else if (message.getMethod() == "zoomvertical") { + + Pane *pane = m_paneStack->getCurrentPane(); + Layer *layer = 0; + if (pane && pane->getLayerCount() > 0) { + layer = pane->getLayer(pane->getLayerCount() - 1); + } + int defaultStep = 0; + int steps = 0; + if (layer) { + steps = layer->getVerticalZoomSteps(defaultStep); + if (message.getArgCount() == 1 && steps > 0) { + if (message.getArg(0).canConvert(QVariant::String) && + message.getArg(0).toString() == "in") { + int step = layer->getCurrentVerticalZoomStep() + 1; + if (step < steps) layer->setVerticalZoomStep(step); + } else if (message.getArg(0).canConvert(QVariant::String) && + message.getArg(0).toString() == "out") { + int step = layer->getCurrentVerticalZoomStep() - 1; + if (step >= 0) layer->setVerticalZoomStep(step); + } else if (message.getArg(0).canConvert(QVariant::String) && + message.getArg(0).toString() == "default") { + layer->setVerticalZoomStep(defaultStep); + } + } else if (message.getArgCount() == 2) { + if (message.getArg(0).canConvert(QVariant::Double) && + message.getArg(1).canConvert(QVariant::Double)) { + double min = message.getArg(0).toDouble(); + double max = message.getArg(1).toDouble(); + layer->setDisplayExtents(min, max); + } + } + } + } else if (message.getMethod() == "quit") { m_abandoning = true; @@ -3886,7 +3950,8 @@ Layer *newLayer = m_document->createDerivedLayer (transform, getMainModel(), - PluginTransform::ExecutionContext(), + TransformFactory::getInstance()->getDefaultContextForTransform + (transform, getMainModel()), ""); if (newLayer) {
--- a/main/MainWindow.h Tue Nov 14 16:06:00 2006 +0000 +++ b/main/MainWindow.h Wed Nov 15 18:22:26 2006 +0000 @@ -192,6 +192,8 @@ void rightButtonMenuRequested(Pane *, QPoint point); + void propertyStacksResized(); + void preferenceChanged(PropertyContainer::PropertyName); void setupRecentFilesMenu();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/osc/demoscript.sh Wed Nov 15 18:22:26 2006 +0000 @@ -0,0 +1,391 @@ +#!/bin/bash + +audio=$HOME/music +preferred=$audio/ogg/linux +list=audiofiles.txt +used=audiofiles-used.txt + +sv-command quit + +pick_file() +{ + count=`wc -l "$list" 2>/dev/null | awk '{ print $1 }'` + if [ ! -f "$list" ] || [ "$count" -eq "0" ] ; then + find "$audio" -name \*.ogg -print >> "$list" + find "$audio" -name \*.mp3 -print >> "$list" + find "$audio" -name \*.wav -print >> "$list" + find "$preferred" -name \*.ogg -print >> "$list" + find "$preferred" -name \*.mp3 -print >> "$list" + find "$preferred" -name \*.wav -print >> "$list" + count=`wc -l "$list" 2>/dev/null | awk '{ print $1 }'` + fi + while [ -z "$file" ]; do + index=$((RANDOM % $count)) + file=`tail +"$index" "$list" | head -1` + [ -f "$file" ] || continue + done + fgrep -v "$file" "$list" > "$list"_ && mv "$list"_ "$list" + echo "$file" +} + +load_a_file() +{ + file=`pick_file` + if ! sv-command open "$file"; then + pid="`pidof sonic-visualiser`" + if [ -z "$pid" ]; then + ( setsid ../sonic-visualiser & ) + sleep 2 + load_a_file + else + echo "ERROR: Unable to contact sonic-visualiser pid $pid" 1>&2 + exit 1 + fi + fi +} + +show_stuff() +{ + sv-command set overlays 2 + sv-command set zoomwheels 1 + sv-command set propertyboxes 1 +} + +hide_stuff() +{ + sv-command set overlays 0 + sv-command set zoomwheels 0 + sv-command set propertyboxes 0 +} + +reset() +{ + for pane in 1 2 3 4 5; do + for layer in 1 2 3 4 5 6 7 8 9 10; do + sv-command delete layer + done + sv-command delete pane + done + sv-command zoom default + sv-command add waveform + show_stuff +} + +scroll_and_zoom() +{ + sv-command set overlays 0 + sv-command set zoomwheels 0 + sv-command set propertyboxes 0 + sv-command setcurrent 1 1 + sv-command delete layer + sv-command setcurrent 1 1 + sv-command set layer Colour Red + sleep 1 + sv-command set pane Global-Zoom off + sv-command set pane Global-Scroll off + sv-command set pane Follow-Playback Scroll + for zoom in 950 900 850 800 750 700 650 600 550 512 450 400 350 300 256 192 160 128 96 64 48 32 24 16; do + sv-command zoom $zoom + sleep 0.1 + done +} + +play() +{ + sv-command play "$@" +} + +fade_in() +{ + sv-command set gain 0 + sleep 0.5 + play "$@" + for gain in 0.001 0.01 0.05 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1; do + sv-command set gain $gain + sleep 0.1 + done +} + +fade_out() +{ + for gain in 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0.05 0.01 0.001; do + sv-command set gain $gain + sleep 0.1 + done + stop + sv-command set gain 1 +} + +slow() +{ + for speed in -1 -10 -20 -30 -40 -50 -60 -70 -80 -100 -140 -200 -250 -300 -400 -500 -700 -800 -900 -1000; do + sv-command set speedup "$speed" + sleep 1 + done +} + +stop() +{ + sv-command stop "$@" + sv-command set speedup 0 +} + +quit() +{ + sv-command quit +} + +add_melodic_range_spectrogram() +{ + sv-command set propertyboxes 1 + sv-command add spectrogram + sv-command set layer Window-Size 4096 +# sv-command set layer Window-Overlap 4 + sv-command set layer Window-Overlap 3 + sv-command set layer Frequency-Scale Log + sv-command set layer Colour-Scale Meter +} + +zoom_in_spectrogram() +{ + sv-command zoomvertical 43 8000 + for x in 1 2 3 4 5 6; do + max=$((8000 - 1000*$x)) + sv-command zoomvertical 43 "$max" + sleep 0.1 + done + for x in 1 2 3 4 5; do + max=$((2000 - 100 * $x)) + sv-command zoomvertical 43 "$max" + sleep 0.1 + done +} + +zoom_in_spectrogram_further() +{ + for x in 1 2 3 4 5; do + sv-command zoomvertical in + done +} + +playback_bits() +{ + sv-command set pane Follow-Playback Scroll + sv-command jump 10 + sv-command setcurrent 1 2 + sv-command set layer Colour Blue + sleep 5 + hide_stuff + fade_in + sleep 10 + scroll_and_zoom + sleep 10 + slow + #sv-command set layer Normalize-Visible-Area on + for zoom in 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1; do + sv-command zoom $zoom + sleep 0.1 + done + sleep 8 + fade_out + done_playback_bits=1 +} + +spectrogram_bits() +{ + add_melodic_range_spectrogram + sv-command zoom 256 + sleep 10 + zoom_in_spectrogram + sleep 20 + + if [ -n "$done_playback_bits" ]; then + sv-command setcurrent 1 + sv-command zoom out + sv-command zoom out + sv-command zoom out + sv-command zoom out + sv-command zoom out + sv-command setcurrent 2 + fi + + hide_stuff + fade_in + sleep 10 + sv-command set layer Bin-Display Frequencies + sv-command set layer Normalize-Columns on + sleep 20 + sv-command set layer Bin-Display "All Bins" + sv-command set layer Colour "Red on Blue" + sleep 10 + fade_out + sleep 1 + done_spectrogram_bits=1 + +# zoom_in_spectrogram_further +} + +onset_bits() +{ + show_stuff + sv-command setcurrent 1 + sv-command set pane Global-Zoom on + sv-command set pane Global-Scroll on + sleep 5 + sv-command zoom default + sv-command zoom in + sv-command zoom in + sv-command zoom in + sv-command add timeruler + sv-command transform vamp:vamp-aubio:aubioonset:detectionfunction + sleep 5 + sv-command set layer Plot-Type Curve + sleep 5 + sv-command setcurrent 1 + sv-command set pane Follow-Playback Page + sv-command transform vamp:vamp-aubio:aubioonset:detectionfunction + sv-command set layer Colour Red + sleep 5 + sv-command set layer Plot-Type Segmentation +# sv-command set layer Vertical-Scale "Log Scale" + sv-command jump 30 + sleep 5 +# hide_stuff + if [ -n "$done_spectrogram_bits" ]; then + sv-command setcurrent 2 + sv-command delete pane + fi + sleep 10 + sv-command setcurrent 1 1 + sv-command set layer Colour Black + sv-command setcurrent 1 2 + fade_in + sleep 5 + sv-command transform vamp:vamp-aubio:aubioonset:onsets + sv-command set layer Colour Black + sleep 20 + sv-command setcurrent 2 +# sv-command transform vamp:qm-vamp-plugins:qm-tempotracker:beats + sv-command transform vamp:vamp-aubio:aubiotempo:beats + sleep 10 + fade_out + show_stuff +} + +selection_bits() +{ +# reset + sv-command set overlays 1 + sv-command set zoomwheels 0 + sv-command setcurrent 2 + sv-command delete pane + if [ -n "$done_playback_bits" ]; then + sv-command setcurrent 1 2 + else + sv-command setcurrent 1 3 + fi + sv-command delete layer + if [ -n "$done_playback_bits" ]; then + sv-command setcurrent 1 2 + else + sv-command setcurrent 1 3 + fi + sv-command delete layer +# sv-command transform vamp:qm-vamp-plugins:qm-tempotracker:beats + sv-command transform vamp:vamp-aubio:aubiotempo:beats + sv-command setcurrent 1 2 + sv-command set layer Colour Orange + sv-command setcurrent 1 3 + sv-command resize 1024 500 + sv-command zoom default + sleep 10 + sv-command loop on + base=$((RANDOM % 100)) + sv-command select $base $base.3 + fade_in selection + sleep 12 + base=$((base + 4)) + sv-command addselect $base $base.1 + sleep 12 + base=$((base + 2)) + sv-command addselect $base $base.1 + sleep 6 + base=$((base + 2)) + sv-command addselect $base $base.3 + sleep 6 + base=$((base + 3)) + sv-command addselect $base $base.3 + sleep 6 + base=$((base + 2)) + sv-command addselect $base $base.3 + sleep 12 + sv-command set speedup -50 + sleep 14 + sv-command set speedup 50 + sleep 8 + sv-command set speedup 100 + sleep 5 + sv-command set speedup 200 + fade_out + sleep 20 + sv-command select none + sv-command setcurrent 1 3 + sv-command delete layer + sv-command setcurrent 1 2 + sv-command set layer Colour Black +} + +chromagram_bits() +{ + add_melodic_range_spectrogram + sv-command add timeruler + sv-command transform vamp:qm-vamp-plugins:qm-chromagram:chromagram + sleep 2 + sv-command jump 20 + sleep 10 + sv-command zoom out + fade_in + sleep 10 + fade_out +} + +while /bin/true; do + +sleep 2 +load_a_file +sv-command loop on + +sv-command resize 1024 500 +show_stuff +sleep 10 +playback_bits + +sv-command resize 1024 700 +show_stuff +#sleep 10 +spectrogram_bits + +sv-command jump 0 +sv-command resize 1024 700 +show_stuff +sleep 10 +onset_bits + +selection_bits + +sv-command resize 1024 700 + +sv-command jump 0 +chromagram_bits + +sleep 20 + +pid="`pidof sonic-visualiser`" +if [ -n "$pid" ]; then + kill "$pid" + sleep 2 +else + reset +fi + +done
--- a/osc/sv-command Tue Nov 14 16:06:00 2006 +0000 +++ b/osc/sv-command Wed Nov 15 18:22:26 2006 +0000 @@ -52,3 +52,4 @@ done fi +exit 0
--- a/transform/TransformFactory.cpp Tue Nov 14 16:06:00 2006 +0000 +++ b/transform/TransformFactory.cpp Wed Nov 15 18:22:26 2006 +0000 @@ -623,6 +623,27 @@ return ok ? inputModel : 0; } +PluginTransform::ExecutionContext +TransformFactory::getDefaultContextForTransform(TransformName name, + Model *inputModel) +{ + PluginTransform::ExecutionContext context(-1); + + QString id = name.section(':', 0, 2); + + if (FeatureExtractionPluginFactory::instanceFor(id)) { + + Vamp::Plugin *vp = + FeatureExtractionPluginFactory::instanceFor(id)->instantiatePlugin + (id, inputModel ? inputModel->getSampleRate() : 48000); + + if (vp) context = PluginTransform::ExecutionContext(-1, vp); + + } + + return context; +} + Transform * TransformFactory::createTransform(TransformName name, Model *inputModel, const PluginTransform::ExecutionContext &context,
--- a/transform/TransformFactory.h Tue Nov 14 16:06:00 2006 +0000 +++ b/transform/TransformFactory.h Wed Nov 15 18:22:26 2006 +0000 @@ -90,6 +90,13 @@ AudioCallbackPlaySource *source = 0); /** + * Get the default execution context for the given transform + * and input model (if known). + */ + PluginTransform::ExecutionContext getDefaultContextForTransform(TransformName name, + Model *inputModel = 0); + + /** * Return the output model resulting from applying the named * transform to the given input model. The transform may still be * working in the background when the model is returned; check the