Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User Preference to Hide beat grid on waveform #1247

Merged
merged 6 commits into from
Jul 23, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/preferences/dialog/dlgprefwaveform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ DlgPrefWaveform::DlgPrefWaveform(QWidget* pParent, MixxxMainWindow* pMixxx,
this, SLOT(slotSetVisualGainHigh(double)));
connect(normalizeOverviewCheckBox, SIGNAL(toggled(bool)),
this, SLOT(slotSetNormalizeOverview(bool)));
connect(beatGridLinesCheckBox, SIGNAL(toggled(bool)),
this, SLOT(slotSetGridLines(bool)));
connect(factory, SIGNAL(waveformMeasured(float,int)),
this, SLOT(slotWaveformMeasured(float,int)));
connect(waveformOverviewComboBox, SIGNAL(currentIndexChanged(int)),
Expand Down Expand Up @@ -102,6 +104,7 @@ void DlgPrefWaveform::slotUpdate() {
highVisualGain->setValue(factory->getVisualGain(WaveformWidgetFactory::High));
normalizeOverviewCheckBox->setChecked(factory->isOverviewNormalized());
defaultZoomComboBox->setCurrentIndex(factory->getDefaultZoom() - 1);
beatGridLinesCheckBox->setChecked(factory->isBeatGridEnabled());

// By default we set RGB woverview = "2"
int overviewType = m_pConfig->getValue(
Expand Down Expand Up @@ -159,6 +162,9 @@ void DlgPrefWaveform::slotResetToDefaults() {
// Waveform caching enabled.
enableWaveformCaching->setChecked(true);
enableWaveformGenerationWithAnalysis->setChecked(false);

// Beat grid lines on waveform is default
beatGridLinesCheckBox->setChecked(true);
}

void DlgPrefWaveform::slotSetFrameRate(int frameRate) {
Expand Down Expand Up @@ -226,6 +232,10 @@ void DlgPrefWaveform::slotClearCachedWaveforms() {
}
}

void DlgPrefWaveform::slotSetGridLines(bool displayGrid) {
WaveformWidgetFactory::instance()->setDisplayBeatGrid(displayGrid);
}

void DlgPrefWaveform::calculateCachedWaveformDiskUsage() {
TrackCollection* pTrackCollection = m_pLibrary->getTrackCollection();
if (pTrackCollection != nullptr) {
Expand Down
1 change: 1 addition & 0 deletions src/preferences/dialog/dlgprefwaveform.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class DlgPrefWaveform : public DlgPreferencePage, public Ui::DlgPrefWaveformDlg
void slotSetNormalizeOverview(bool normalize);
void slotWaveformMeasured(float frameRate, int droppedFrames);
void slotClearCachedWaveforms();
void slotSetGridLines(bool displayGrid);

private:
void initWaveformControl();
Expand Down
23 changes: 23 additions & 0 deletions src/preferences/dialog/dlgprefwaveformdlg.ui
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="QLabel" name="BeatgridWaveform">
<property name="toolTip">
<string/>
</property>
<property name="text">
<string>Display grid lines on waveform</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="frameRateLabel">
<property name="text">
Expand Down Expand Up @@ -330,6 +343,16 @@
</property>
</widget>
</item>
<item row="12" column="1">
<widget class="QCheckBox" name="beatGridLinesCheckBox">
<property name="toolTip">
<string>Beat Grid</string>
</property>
<property name="text">
<string>Show Beat Markers</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="endOfTrackWarningTimeLabel">
<property name="text">
Expand Down
3 changes: 3 additions & 0 deletions src/waveform/renderers/waveformrenderbeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ void WaveformRenderBeat::draw(QPainter* painter, QPaintEvent* /*event*/) {
if (!trackBeats)
return;

if (!m_waveformRenderer->isBeatGridEnabled())
return;

const int trackSamples = m_waveformRenderer->getTrackSamples();
if (trackSamples <= 0) {
return;
Expand Down
5 changes: 5 additions & 0 deletions src/waveform/renderers/waveformwidgetrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ WaveformWidgetRenderer::WaveformWidgetRenderer(const char* group)
m_rateAdjust(0.0),
m_visualSamplePerPixel(1.0),
m_audioSamplePerPixel(1.0),
m_enableBeatGrid(true),

// Really create some to manage those;
m_visualPlayPosition(NULL),
Expand Down Expand Up @@ -274,6 +275,10 @@ void WaveformWidgetRenderer::setZoom(int zoom) {
m_zoomFactor = math_clamp<double>(zoom, s_waveformMinZoom, s_waveformMaxZoom);
}

void WaveformWidgetRenderer::setDisplayBeatGrid(bool set) {
m_enableBeatGrid = set;
}

void WaveformWidgetRenderer::setTrack(TrackPointer track) {
m_pTrack = track;
//used to postpone first display until track sample is actually available
Expand Down
6 changes: 6 additions & 0 deletions src/waveform/renderers/waveformwidgetrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class WaveformWidgetRenderer {

void setZoom(int zoom);

void setDisplayBeatGrid(bool set);

double getVisualSamplePerPixel() const { return m_visualSamplePerPixel;};
double getAudioSamplePerPixel() const { return m_audioSamplePerPixel;};

Expand Down Expand Up @@ -71,6 +73,8 @@ class WaveformWidgetRenderer {
double getGain() const { return m_gain;}
int getTrackSamples() const { return m_trackSamples;}

bool isBeatGridEnabled() const { return m_enableBeatGrid; }

void resize(int width, int height);
int getHeight() const { return m_height;}
int getWidth() const { return m_width;}
Expand Down Expand Up @@ -106,6 +110,8 @@ class WaveformWidgetRenderer {
double m_visualSamplePerPixel;
double m_audioSamplePerPixel;

bool m_enableBeatGrid;

//TODO: vRince create some class to manage control/value
//ControlConnection
QSharedPointer<VisualPlayPosition> m_visualPlayPosition;
Expand Down
25 changes: 25 additions & 0 deletions src/waveform/waveformwidgetfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ WaveformWidgetFactory::WaveformWidgetFactory() :
m_overviewNormalized(false),
m_openGLAvailable(false),
m_openGLShaderAvailable(false),
m_beatGridEnabled(true),
m_vsyncThread(NULL),
m_frameCnt(0),
m_actualFrameRate(0),
Expand Down Expand Up @@ -223,6 +224,13 @@ bool WaveformWidgetFactory::setConfig(UserSettingsPointer config) {
m_config->set(ConfigKey("[Waveform]","ZoomSynchronization"), ConfigValue(m_zoomSync));
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can simplify the code passing the default value

int showBeatGrid = m_config->getValue("[Waveform]", "beatGridLinesCheckBox", m_showBeatGrid)

(not sure about the exact syntax though)

int showBeatGrid = m_config->getValue(ConfigKey("[Waveform]", "beatGridLinesCheckBox")).toInt(&ok);
if (ok) {
setDisplayBeatGrid(static_cast<bool>(showBeatGrid));
} else {
m_config->set(ConfigKey("[Waveform]", "beatGridLinesCheckBox"), ConfigValue(m_beatGridEnabled));
}

WaveformWidgetType::Type type = static_cast<WaveformWidgetType::Type>(
m_config->getValueString(ConfigKey("[Waveform]","WaveformType")).toInt(&ok));
if (!ok || !setWidgetType(type)) {
Expand Down Expand Up @@ -296,6 +304,7 @@ bool WaveformWidgetFactory::setWaveformWidget(WWaveformViewer* viewer,
}

viewer->setZoom(m_defaultZoom);
viewer->setDisplayBeatGrid(m_beatGridEnabled);
viewer->update();

qDebug() << "WaveformWidgetFactory::setWaveformWidget - waveform widget added in factory, index" << index;
Expand Down Expand Up @@ -432,6 +441,22 @@ void WaveformWidgetFactory::setZoomSync(bool sync) {
}
}

void WaveformWidgetFactory::setDisplayBeatGrid(bool sync) {
m_beatGridEnabled = sync;
if (m_config) {
m_config->set(ConfigKey("[Waveform]", "beatGridLinesCheckBox"), ConfigValue(m_beatGridEnabled));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we normally do not set the value, if not required. We try to load the value and if it fails pick the default. Is it required here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dlgprefwaveform calls this in order to update the Config
void DlgPrefWaveform::slotSetGridLines(bool displayGrid) { WaveformWidgetFactory::instance()->setDisplayBeatGrid(displayGrid); }

Would there be a better way to do this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make more sense to set the ConfigKey in DlgPrefWaveform than here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see the way you did it is consistent with the surrounding code. You don't have to clean this up if you don't have time, but it would be nice to move the setting of the ConfigKeys into DlgPrefWaveform.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I do this just for the display grid preference?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, keep it consistent. Either leave it how it is or refactor how all the settings in this function are set.

}

if (m_waveformWidgetHolders.size() == 0) {
return;
}

for (int i = 0; i < m_waveformWidgetHolders.size(); i++) {
m_waveformWidgetHolders[i].m_waveformWidget->setDisplayBeatGrid(m_beatGridEnabled);
}

}

void WaveformWidgetFactory::setVisualGain(FilterIndex index, double gain) {
m_visualGain[index] = gain;
if (m_config)
Expand Down
4 changes: 4 additions & 0 deletions src/waveform/waveformwidgetfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class WaveformWidgetFactory : public QObject, public Singleton<WaveformWidgetFac
void setZoomSync(bool sync);
int isZoomSync() const { return m_zoomSync;}

void setDisplayBeatGrid(bool sync);
bool isBeatGridEnabled() const { return m_beatGridEnabled; }

void setVisualGain(FilterIndex index, double gain);
double getVisualGain(FilterIndex index) const;

Expand Down Expand Up @@ -148,6 +151,7 @@ class WaveformWidgetFactory : public QObject, public Singleton<WaveformWidgetFac
bool m_openGLAvailable;
QString m_openGLVersion;
bool m_openGLShaderAvailable;
bool m_beatGridEnabled;

VSyncThread* m_vsyncThread;

Expand Down
4 changes: 4 additions & 0 deletions src/widget/wwaveformviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ void WWaveformViewer::setZoom(int zoom) {
}
}

void WWaveformViewer::setDisplayBeatGrid(bool set) {
m_waveformWidget->setDisplayBeatGrid(set);
}

void WWaveformViewer::setWaveformWidget(WaveformWidgetAbstract* waveformWidget) {
if (m_waveformWidget) {
QWidget* pWidget = m_waveformWidget->getWidget();
Expand Down
1 change: 1 addition & 0 deletions src/widget/wwaveformviewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private slots:
}
//direct access to let factory sync/set default zoom
void setZoom(int zoom);
void setDisplayBeatGrid(bool set);

private:
const char* m_pGroup;
Expand Down