~s-cecilio/lenmus/v5.1.x

« back to all changes in this revision

Viewing changes to src/sound/Metronome.cpp

  • Committer: cecilios
  • Date: 2006-03-05 11:33:10 UTC
  • Revision ID: svn-v4:2587a929-2f0e-0410-ae78-fe6f687d5efe:trunk:2
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
5
//
 
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.
 
9
//
 
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.
 
13
//
 
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.
 
17
//
 
18
//    For any comment, suggestion or feature request, please contact the manager of 
 
19
//    the project at cecilios@users.sourceforge.net
 
20
//
 
21
//-------------------------------------------------------------------------------------
 
22
/*! @file Metronome.cpp
 
23
    @brief Implementation file for class lmMetronome
 
24
    @ingroup sound_management
 
25
*/
 
26
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
 
27
#pragma implementation "Metronome.h"
 
28
#endif
 
29
 
 
30
// For compilers that support precompilation, includes "wx.h".
 
31
#include "wx/wxprec.h"
 
32
 
 
33
#ifdef __BORLANDC__
 
34
#pragma hdrstop
 
35
#endif
 
36
 
 
37
#include "Metronome.h"
 
38
 
 
39
//access to lmMidiManager
 
40
#include "../sound/MidiManager.h"
 
41
 
 
42
 
 
43
    //
 
44
    // lmMetronomeTimer implementation
 
45
    //
 
46
 
 
47
void lmMetronomeTimer::Notify()
 
48
{
 
49
    m_pOwner->OnTimerEvent();
 
50
}
 
51
 
 
52
    //
 
53
    // lmMetronome implementation
 
54
    //
 
55
 
 
56
lmMetronome::lmMetronome(long nMM)
 
57
{
 
58
    m_pTimer = (lmMetronomeTimer*)NULL;
 
59
    SetMM(nMM);
 
60
    m_fEnabled = true;
 
61
    m_fRunning = false;
 
62
}
 
63
 
 
64
lmMetronome::~lmMetronome()
 
65
{
 
66
    if (m_pTimer) delete m_pTimer;
 
67
}
 
68
 
 
69
void lmMetronome::Start()
 
70
{
 
71
    if (!m_pTimer) {
 
72
        //create the timer
 
73
        m_pTimer = new lmMetronomeTimer(this);
 
74
    }
 
75
    m_pTimer->Start(m_nInterval);
 
76
    m_fRunning = true;
 
77
 
 
78
}
 
79
 
 
80
void lmMetronome::Stop()
 
81
{
 
82
    if (m_pTimer) {
 
83
        m_pTimer->Stop();
 
84
    }
 
85
    m_fRunning = false;
 
86
 
 
87
}
 
88
 
 
89
void lmMetronome::SetMM(long nMM)
 
90
{
 
91
    m_nInterval = (60000 / nMM);
 
92
    m_nMM = nMM;
 
93
}
 
94
 
 
95
void lmMetronome::SetInterval(long milliseconds)
 
96
{
 
97
    m_nInterval = milliseconds;
 
98
    m_nMM = (long)((60000.0 / (float)milliseconds)+ 0.5);;
 
99
}
 
100
 
 
101
void lmMetronome::OnTimerEvent()
 
102
{
 
103
    //! @todo metronome LED
 
104
 
 
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
 
107
    //table processing.
 
108
    if (m_fEnabled) {
 
109
        m_pTimer->Start(m_nInterval);
 
110
        //Me.picMtrLEDOff.Visible = False
 
111
        //Me.picMtrLEDRojoOn.Visible = True
 
112
        
 
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);
 
117
 
 
118
        // flash metronome LED
 
119
        //Me.picMtrLEDOff.Visible = True
 
120
        //Me.picMtrLEDRojoOn.Visible = False
 
121
    }
 
122
}