svcore  1.9
PlayParameters.cpp
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2006 Chris Cannam.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #include "PlayParameters.h"
00017 
00018 #include <iostream>
00019 
00020 #include <QTextStream>
00021 
00022 void
00023 PlayParameters::copyFrom(const PlayParameters *pp)
00024 {
00025     bool changed = false;
00026 
00027     if (m_playMuted != pp->isPlayMuted()) {
00028         m_playMuted = pp->isPlayMuted();
00029         emit playMutedChanged(m_playMuted);
00030         emit playAudibleChanged(!m_playMuted);
00031         changed = true;
00032     }
00033 
00034     if (m_playPan != pp->getPlayPan()) {
00035         m_playPan = pp->getPlayPan();
00036         emit playPanChanged(m_playPan);
00037         changed = true;
00038     }
00039 
00040     if (m_playGain != pp->getPlayGain()) {
00041         m_playGain = pp->getPlayGain();
00042         emit playGainChanged(m_playGain);
00043         changed = true;
00044     }
00045 
00046     if (m_playClipId != pp->getPlayClipId()) {
00047         m_playClipId = pp->getPlayClipId();
00048         emit playClipIdChanged(m_playClipId);
00049         changed = true;
00050     }
00051 
00052     if (changed) emit playParametersChanged();
00053 }
00054 
00055 void
00056 PlayParameters::toXml(QTextStream &stream,
00057                       QString indent,
00058                       QString extraAttributes) const
00059 {
00060     stream << indent;
00061     stream << QString("<playparameters mute=\"%1\" pan=\"%2\" gain=\"%3\" clipId=\"%4\" %6")
00062         .arg(m_playMuted ? "true" : "false")
00063         .arg(m_playPan)
00064         .arg(m_playGain)
00065         .arg(m_playClipId)
00066         .arg(extraAttributes);
00067 
00068     stream << ">\n";
00069 
00070     if (m_playClipId != "") {
00071         // for backward compatibility
00072         stream << indent << "  ";
00073         stream << QString("<plugin identifier=\"%1\" program=\"%2\"/>\n")
00074             .arg("sample_player")
00075             .arg(m_playClipId);
00076     }
00077 
00078     stream << indent << "</playparameters>\n";
00079 }
00080 
00081 void
00082 PlayParameters::setPlayMuted(bool muted)
00083 {
00084 //    cerr << "PlayParameters: setPlayMuted(" << muted << ")" << endl;
00085     if (m_playMuted != muted) {
00086         m_playMuted = muted;
00087         emit playMutedChanged(muted);
00088         emit playAudibleChanged(!muted);
00089         emit playParametersChanged();
00090     }
00091 }
00092 
00093 void
00094 PlayParameters::setPlayAudible(bool audible)
00095 {
00096 //    cerr << "PlayParameters(" << this << "): setPlayAudible(" << audible << ")" << endl;
00097     setPlayMuted(!audible);
00098 }
00099 
00100 void
00101 PlayParameters::setPlayPan(float pan)
00102 {
00103     if (m_playPan != pan) {
00104         m_playPan = pan;
00105         emit playPanChanged(pan);
00106         emit playParametersChanged();
00107     }
00108 }
00109 
00110 void
00111 PlayParameters::setPlayGain(float gain)
00112 {
00113     if (m_playGain != gain) {
00114         m_playGain = gain;
00115         emit playGainChanged(gain);
00116         emit playParametersChanged();
00117     }
00118 }
00119 
00120 void
00121 PlayParameters::setPlayClipId(QString id)
00122 {
00123     if (m_playClipId != id) {
00124         m_playClipId = id;
00125         emit playClipIdChanged(id);
00126         emit playParametersChanged();
00127     }
00128 }