Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Binary file added data/themes/default/metronome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions include/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ public slots:

QMenu * m_viewMenu;

ToolButton * m_metronomeToggle;

private slots:
void browseHelp();
void fillTemplatesMenu();
Expand All @@ -193,6 +195,7 @@ private slots:
void updateRecentlyOpenedProjectsMenu();
void updateViewMenu( void );
void updateConfig( QAction * _who );
void onToggleMetronome();


void autoSave();
Expand Down
5 changes: 5 additions & 0 deletions include/Mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ class EXPORT Mixer : public QObject

void changeQuality( const struct qualitySettings & _qs );

inline bool isMetronomeActive() const { return m_metronomeActive; }
inline void setMetronomeActive(bool value = true) { m_metronomeActive = value; }


signals:
void qualitySettingsChanged();
Expand Down Expand Up @@ -457,6 +460,8 @@ class EXPORT Mixer : public QObject

MixerProfiler m_profiler;

bool m_metronomeActive;

friend class Engine;
friend class MixerWorkerThread;

Expand Down
33 changes: 22 additions & 11 deletions src/core/Mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ Mixer::Mixer( bool renderOnly ) :
m_audioDev( NULL ),
m_oldAudioDev( NULL ),
m_globalMutex( QMutex::Recursive ),
m_profiler()
m_profiler(),
m_metronomeActive(false)
{
for( int i = 0; i < 2; ++i )
{
Expand Down Expand Up @@ -318,28 +319,37 @@ const surroundSampleFrame * Mixer::renderNextBuffer()

static Song::PlayPos last_metro_pos = -1;

Song::PlayPos p = Engine::getSong()->getPlayPos(
Song::Mode_PlayPattern );
if( Engine::getSong()->playMode() == Song::Mode_PlayPattern &&
gui->pianoRoll()->isRecording() == true &&
Song *song = Engine::getSong();

Song::PlayModes currentPlayMode = song->playMode();
Song::PlayPos p = song->getPlayPos( currentPlayMode );

bool playModeSupportsMetronome = currentPlayMode == Song::Mode_PlayPattern ||
currentPlayMode == Song::Mode_PlaySong ||
currentPlayMode == Song::Mode_PlayBB;

if( playModeSupportsMetronome && m_metronomeActive && !song->isExporting() &&
p != last_metro_pos )
{
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of decomposing the conditional a bit? Maybe something like:

bool isPlaying = currentPlayMode == Song::Mode_PlayPattern || currentPlayMode == Song::Mode_PlaySong
         || currentPlayMode == Song::Mode_PlayBB;
if (isPlaying && m_metronomeActive && !Engine::getSong()->isExporting() &&
        p != last_metro_pos) ...

Hope I'm not being too pedantic. Everything else looks good.

if ( p.getTicks() % (MidiTime::ticksPerTact() / 1 ) == 0 )
tick_t ticksPerTact = MidiTime::ticksPerTact();
if ( p.getTicks() % (ticksPerTact / 1 ) == 0 )
{
addPlayHandle( new SamplePlayHandle( "misc/metronome02.ogg" ) );
}
else if ( p.getTicks() % (MidiTime::ticksPerTact() /
Engine::getSong()->getTimeSigModel().getNumerator() ) == 0 )
else if ( p.getTicks() % (ticksPerTact /
song->getTimeSigModel().getNumerator() ) == 0 )
{
addPlayHandle( new SamplePlayHandle( "misc/metronome01.ogg" ) );
}
last_metro_pos = p;
}

lockInputFrames();

// swap buffer
m_inputBufferWrite = ( m_inputBufferWrite + 1 ) % 2;
m_inputBufferRead = ( m_inputBufferRead + 1 ) % 2;

// clear new write buffer
m_inputBufferFrames[ m_inputBufferWrite ] = 0;
unlockInputFrames();
Expand Down Expand Up @@ -383,10 +393,11 @@ const surroundSampleFrame * Mixer::renderNextBuffer()
clearAudioBuffer( m_writeBuf, m_framesPerPeriod );

// prepare master mix (clear internal buffers etc.)
Engine::fxMixer()->prepareMasterMix();
FxMixer * fxMixer = Engine::fxMixer();
fxMixer->prepareMasterMix();

// create play-handles for new notes, samples etc.
Engine::getSong()->processNextBuffer();
song->processNextBuffer();

// add all play-handles that have to be added
m_playHandleMutex.lock();
Expand Down Expand Up @@ -432,7 +443,7 @@ const surroundSampleFrame * Mixer::renderNextBuffer()


// STAGE 3: do master mix in FX mixer
Engine::fxMixer()->masterMix( m_writeBuf );
fxMixer->masterMix( m_writeBuf );

unlock();

Expand Down
22 changes: 21 additions & 1 deletion src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ MainWindow::MainWindow() :
m_recentlyOpenedProjectsMenu( NULL ),
m_toolsMenu( NULL ),
m_autoSaveTimer( this ),
m_viewMenu( NULL )
m_viewMenu( NULL ),
m_metronomeToggle( 0 )
{
setAttribute( Qt::WA_DeleteOnClose );

Expand Down Expand Up @@ -430,6 +431,13 @@ void MainWindow::finalize()
this, SLOT( enterWhatsThisMode() ),
m_toolBar );

m_metronomeToggle = new ToolButton(
embed::getIconPixmap( "metronome" ),
tr( "Toggle metronome" ),
this, SLOT( onToggleMetronome() ),
m_toolBar );
m_metronomeToggle->setCheckable(true);
m_metronomeToggle->setChecked(Engine::mixer()->isMetronomeActive());

m_toolBarLayout->setColumnMinimumWidth( 0, 5 );
m_toolBarLayout->addWidget( project_new, 0, 1 );
Expand All @@ -439,6 +447,7 @@ void MainWindow::finalize()
m_toolBarLayout->addWidget( project_save, 0, 5 );
m_toolBarLayout->addWidget( project_export, 0, 6 );
m_toolBarLayout->addWidget( whatsthis, 0, 7 );
m_toolBarLayout->addWidget( m_metronomeToggle, 0, 8 );


// window-toolbar
Expand Down Expand Up @@ -1209,6 +1218,17 @@ void MainWindow::updateConfig( QAction * _who )
}



void MainWindow::onToggleMetronome()
{
Mixer * mixer = Engine::mixer();

mixer->setMetronomeActive( m_metronomeToggle->isChecked() );
}




void MainWindow::toggleControllerRack()
{
toggleWindow( gui->getControllerRackView() );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/editors/SongEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ SongEditor::SongEditor( Song * _song ) :
// add some essential widgets to global tool-bar
QWidget * tb = gui->mainWindow()->toolBar();

gui->mainWindow()->addSpacingToToolBar( 10 );
gui->mainWindow()->addSpacingToToolBar( 40 );

m_tempoSpinBox = new LcdSpinBox( 3, tb, tr( "Tempo" ) );
m_tempoSpinBox->setModel( &m_song->m_tempoModel );
Expand Down