1
// RCS-ID: $Id: Metronome.cpp,v 1.3 2006/02/23 19:25:44 cecilios Exp $
2
//--------------------------------------------------------------------------------------
3
// LenMus Phonascus: The teacher of music
4
// Copyright (c) 2002-2006 Cecilio Salmeron
6
// This program is free software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the Free Software Foundation;
8
// either version 2 of the License, or (at your option) any later version.
10
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
11
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12
// PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License along with this
15
// program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
16
// Fifth Floor, Boston, MA 02110-1301, USA.
18
// For any comment, suggestion or feature request, please contact the manager of
19
// the project at cecilios@users.sourceforge.net
21
//-------------------------------------------------------------------------------------
22
/*! @file Metronome.cpp
23
@brief Implementation file for class lmMetronome
24
@ingroup sound_management
26
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
27
#pragma implementation "Metronome.h"
30
// For compilers that support precompilation, includes "wx.h".
31
#include "wx/wxprec.h"
37
#include "Metronome.h"
39
//access to lmMidiManager
40
#include "../sound/MidiManager.h"
44
// lmMetronomeTimer implementation
47
void lmMetronomeTimer::Notify()
49
m_pOwner->OnTimerEvent();
53
// lmMetronome implementation
56
lmMetronome::lmMetronome(long nMM)
58
m_pTimer = (lmMetronomeTimer*)NULL;
64
lmMetronome::~lmMetronome()
66
if (m_pTimer) delete m_pTimer;
69
void lmMetronome::Start()
73
m_pTimer = new lmMetronomeTimer(this);
75
m_pTimer->Start(m_nInterval);
80
void lmMetronome::Stop()
89
void lmMetronome::SetMM(long nMM)
91
m_nInterval = (60000 / nMM);
95
void lmMetronome::SetInterval(long milliseconds)
97
m_nInterval = milliseconds;
98
m_nMM = (long)((60000.0 / (float)milliseconds)+ 0.5);;
101
void lmMetronome::OnTimerEvent()
103
//! @todo metronome LED
105
//If metronome active and not playing, generate metronome click. If currently playing
106
//the metronome clicks will be generated by lmSoundManager.Play() as part of the MIDI events
109
m_pTimer->Start(m_nInterval);
110
//Me.picMtrLEDOff.Visible = False
111
//Me.picMtrLEDRojoOn.Visible = True
113
// generate metronome click
114
g_pMidiOut->NoteOn(g_pMidi->MtrChannel(), g_pMidi->MtrTone1(), 127);
115
::wxMilliSleep(100); //wait for 100 ms
116
g_pMidiOut->NoteOff(g_pMidi->MtrChannel(), g_pMidi->MtrTone1(), 127);
118
// flash metronome LED
119
//Me.picMtrLEDOff.Visible = True
120
//Me.picMtrLEDRojoOn.Visible = False