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

627 by cecilios
cleaning and commit recent work
1
//---------------------------------------------------------------------------------------
2
//    LenMus Phonascus: The teacher of music
640 by cecilios
Fixed bug with tied notes in composer. Fixed memory leaks in FragmentsTable. Updates checker implemented.Language files reviewed.
3
//    Copyright (c) 2002-2012 LenMus project
627 by cecilios
cleaning and commit recent work
4
//
5
//    This program is free software; you can redistribute it and/or modify it under the
6
//    terms of the GNU General Public License as published by the Free Software Foundation,
7
//    either version 3 of the License, or (at your option) any later version.
8
//
9
//    This program is distributed in the hope that it will be useful, but WITHOUT ANY
10
//    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11
//    PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12
//
13
//    You should have received a copy of the GNU General Public License along with this
14
//    program. If not, see <http://www.gnu.org/licenses/>.
15
//
16
//    For any comment, suggestion or feature request, please contact the manager of
17
//    the project at cecilios@users.sourceforge.net
18
//
19
//---------------------------------------------------------------------------------------
20
21
#ifndef __LENMUS_EXERCISE_CTROL_H__        //to avoid nested includes
22
#define __LENMUS_EXERCISE_CTROL_H__
23
24
//lenmus
634 by cecilios
starting eBooks conversion
25
#include "lenmus_standard_header.h"
627 by cecilios
cleaning and commit recent work
26
#include "lenmus_dyncontrol.h"
27
#include "lenmus_constrains.h"
634 by cecilios
starting eBooks conversion
28
#include "lenmus_counters_ctrol.h"
29
#include "lenmus_events.h"
627 by cecilios
cleaning and commit recent work
30
31
//wxWidgets
32
#include <wx/wxprec.h>
33
#include <wx/wx.h>
634 by cecilios
starting eBooks conversion
34
#include <wx/event.h>
627 by cecilios
cleaning and commit recent work
35
36
//lomse
37
#include <lomse_events.h>
634 by cecilios
starting eBooks conversion
38
#include <lomse_hyperlink_ctrl.h>
640 by cecilios
Fixed bug with tied notes in composer. Fixed memory leaks in FragmentsTable. Updates checker implemented.Language files reviewed.
39
#include <lomse_player_gui.h>
627 by cecilios
cleaning and commit recent work
40
using namespace lomse;
41
42
43
namespace lenmus
44
{
45
46
// forward declarations
47
class DocumentCanvas;
633 by cecilios
last work before vacation
48
class ProblemManager;
634 by cecilios
starting eBooks conversion
49
class CountersCtrol;
50
class ProblemDisplayer;
627 by cecilios
cleaning and commit recent work
51
52
53
//--------------------------------------------------------------------------------
54
// An abstract class for any kind of Ctrol included in an eBook.
656 by cecilios
initial commit with all changes for 5.1. See changelog
55
class EBookCtrol : public DynControl, public EventHandler, public PlayerNoGui
627 by cecilios
cleaning and commit recent work
56
{
57
protected:
634 by cecilios
starting eBooks conversion
58
    DocumentWindow*     m_pCanvas;
633 by cecilios
last work before vacation
59
    EBookCtrolOptions*  m_pBaseConstrains;
60
    ImoDynamic*         m_pDyn;
61
    Document*           m_pDoc;
634 by cecilios
starting eBooks conversion
62
    HyperlinkCtrl*      m_pPlayButton;      // "play" button
633 by cecilios
last work before vacation
63
    bool                m_fControlsCreated;
627 by cecilios
cleaning and commit recent work
64
//    bool                m_fDoCountOff;
65
66
634 by cecilios
starting eBooks conversion
67
    EBookCtrol(long dynId, ApplicationScope& appScope, DocumentWindow* pCanvas);
627 by cecilios
cleaning and commit recent work
68
69
public:
70
    virtual ~EBookCtrol();
71
72
    //implementation of virtual pure in parent DynControl
73
    void generate_content(ImoDynamic* pDyn, Document* pDoc);
634 by cecilios
starting eBooks conversion
74
    virtual void handle_event(SpEventInfo pEvent);
627 by cecilios
cleaning and commit recent work
75
76
    virtual void get_ctrol_options_from_params() = 0;
77
    virtual void initialize_ctrol() = 0;
78
633 by cecilios
last work before vacation
79
    // virtual pure event handlers to be implemented by derived classes
80
    virtual void on_debug_show_source_score()=0;
81
    virtual void on_debug_show_midi_events()=0;
627 by cecilios
cleaning and commit recent work
82
83
    // event handlers. No need to implement in derived classes
84
    virtual void on_play();
85
    virtual void on_settings_button();
633 by cecilios
last work before vacation
86
    virtual void on_go_back();
634 by cecilios
starting eBooks conversion
87
//    virtual void OnDoCountoff(SpEventInfo pEvent);
627 by cecilios
cleaning and commit recent work
88
656 by cecilios
initial commit with all changes for 5.1. See changelog
89
    //overrides of PlayerNoGui for using general metronome for speed settings
90
    int get_metronome_mm();
664 by cecilios
BooksDlg: fixed link to study guide. EBookCtrol fix: override get_metronome() method so that ScorePlayer has access to global metronome. Fix error in CMakeList (reported by mta'chrono)
91
    Metronome* get_metronome();
656 by cecilios
initial commit with all changes for 5.1. See changelog
92
627 by cecilios
cleaning and commit recent work
93
protected:
94
95
    //virtual methods to be implemented by derived classes
96
    virtual void initialize_strings()=0;
97
    virtual wxDialog* get_settings_dialog()=0;
656 by cecilios
initial commit with all changes for 5.1. See changelog
98
    virtual void play(bool fVisualTracking=true)=0;
627 by cecilios
cleaning and commit recent work
99
    virtual void stop_sounds()=0;
633 by cecilios
last work before vacation
100
    virtual void on_settings_changed()=0;
627 by cecilios
cleaning and commit recent work
101
102
    //methods invoked from derived classes
103
//    virtual void create_controls()=0;
104
    virtual void set_buttons(ImoButton* pButton[], int nNumButtons)=0;
105
106
private:
634 by cecilios
starting eBooks conversion
107
//    void do_stop_sounds();
627 by cecilios
cleaning and commit recent work
108
};
109
110
111
112
//---------------------------------------------------------------------------------------
113
// An abstract class for any kind of exercise included in an eBook.
114
class ExerciseCtrol : public EBookCtrol
115
{
116
protected:
634 by cecilios
starting eBooks conversion
117
    ExerciseCtrol(long dynId, ApplicationScope& appScope, DocumentWindow* pCanvas);
627 by cecilios
cleaning and commit recent work
118
119
public:
120
    virtual ~ExerciseCtrol();
121
122
    //mandatory override for EventHandler
634 by cecilios
starting eBooks conversion
123
    virtual void handle_event(SpEventInfo pEvent);
627 by cecilios
cleaning and commit recent work
124
125
    // event handlers. No need to implement in derived classes
126
    virtual void on_resp_button(int iButton);
127
    virtual void on_new_problem();
128
    virtual void on_display_solution();
638 by cecilios
Support for playing scores added to DocumentCanvas
129
    virtual void on_button_mouse_in(SpEventMouse pEvent);
130
    virtual void on_button_mouse_out(SpEventMouse pEvent);
634 by cecilios
starting eBooks conversion
131
//    virtual void OnModeChanged(SpEventInfo pEvent);
132
133
    //other
134
    virtual void OnQuestionAnswered(int iQ, bool fSuccess);
135
    //void change_counters_ctrol();
136
    //void change_generation_mode(int nMode);
137
    //void change_generation_mode_label(int nMode);
138
    void change_mode(int mode);
139
    static void on_exercise_activated(void* pThis, SpEventInfo pEvent);
627 by cecilios
cleaning and commit recent work
140
141
142
protected:
143
    //virtual methods to be implemented by derived classes
144
    virtual void create_answer_buttons(LUnits height, LUnits spacing) = 0;
145
    virtual wxString set_new_problem()=0;
146
    virtual bool check_success_or_failure(int nButton);
634 by cecilios
starting eBooks conversion
147
    void create_display_and_counters();
627 by cecilios
cleaning and commit recent work
148
149
//    virtual void PlaySpecificSound(int nButton)=0;
150
    virtual void display_solution()=0;
634 by cecilios
starting eBooks conversion
151
    virtual void display_problem_score()=0;
627 by cecilios
cleaning and commit recent work
152
    virtual void delete_scores()=0;
633 by cecilios
last work before vacation
153
    virtual void set_problem_space()=0;
627 by cecilios
cleaning and commit recent work
154
155
    //methods that, normally, it is not necessary to implement
156
    virtual void set_button_color(int i, Color color);
157
    virtual void enable_buttons(bool fEnable);
158
    virtual void new_problem();
159
    virtual void reset_exercise();
633 by cecilios
last work before vacation
160
    virtual void set_event_handlers();
640 by cecilios
Fixed bug with tied notes in composer. Fixed memory leaks in FragmentsTable. Updates checker implemented.Language files reviewed.
161
    virtual void create_problem_display_box(ImoContent* pWrapper, ImoStyle* pStyle=NULL);
627 by cecilios
cleaning and commit recent work
162
163
    //methods invoked from derived classes
164
    virtual void create_controls();
165
    void set_buttons(ImoButton* pButton[], int nNumButtons);
166
633 by cecilios
last work before vacation
167
    //internal methods
634 by cecilios
starting eBooks conversion
168
    CountersCtrol* create_counters_ctrol(ImoContent* pWrapper);
633 by cecilios
last work before vacation
169
    void create_problem_manager();
627 by cecilios
cleaning and commit recent work
170
634 by cecilios
starting eBooks conversion
171
    //wrappers for event handlers
172
    static void on_new_problem(void* pThis, SpEventInfo pEvent);
173
    static void on_play_event(void* pThis, SpEventInfo pEvent);
639 by cecilios
Fixed error msg in dlg_ear_intervals. Other changes needed for compatibility with lomse changes. Added debug option for drawing spacers.
174
    //static void on_end_of_play_event(void* pThis, SpEventInfo pEvent);
634 by cecilios
starting eBooks conversion
175
    static void on_display_solution(void* pThis, SpEventInfo pEvent);
176
    static void on_settings(void* pThis, SpEventInfo pEvent);
177
    static void on_see_source_score(void* pThis, SpEventInfo pEvent);
178
    static void on_see_midi_events(void* pThis, SpEventInfo pEvent);
179
    static void on_go_back_event(void* pThis, SpEventInfo pEvent);
180
181
    void change_counters_ctrol();
182
    void change_generation_mode(int nMode);
183
    void change_generation_mode_label(int nMode);
184
627 by cecilios
cleaning and commit recent work
185
186
        // member variables
187
188
    //display control variables
634 by cecilios
starting eBooks conversion
189
    ImoScore*       m_pScoreToPlay;
190
    ProblemDisplayer* m_pDisplay;
627 by cecilios
cleaning and commit recent work
191
634 by cecilios
starting eBooks conversion
192
    CountersCtrol*  m_pCounters;
193
    bool            m_fCountersValid;   //when changing mode counters might not be valid
627 by cecilios
cleaning and commit recent work
194
//    wxChoice*           m_pCboMode;
195
//
633 by cecilios
last work before vacation
196
//    ExerciseOptions*  m_pBaseConstrains;      //constraints for the exercise
627 by cecilios
cleaning and commit recent work
197
    bool                m_fQuestionAsked;   //question asked but not yet answered
198
    int                 m_nRespIndex;       //index to the button with the right answer
199
    int                 m_nRespAltIndex;    //alternative right answer (i.e. enarmonic answer)
200
201
    wxString            m_sAnswer;          //string with the right answer
202
634 by cecilios
starting eBooks conversion
203
    HyperlinkCtrl*     m_pNewProblem;      //"New problem" link
204
    HyperlinkCtrl*     m_pShowSolution;    //"Show solution" link
633 by cecilios
last work before vacation
205
627 by cecilios
cleaning and commit recent work
206
    int                 m_nNumButtons;      //num answer buttons
207
    ImoButton**         m_pAnswerButtons;   //buttons for the answers
208
    long                m_nIdFirstButton;   //ID of first button; the others in sequence
209
210
//    wxSize              m_nDisplaySize;     // DisplayCtrol size (pixels at 1:1)
633 by cecilios
last work before vacation
211
212
    //to generate problems
213
    int                     m_nGenerationMode;
634 by cecilios
starting eBooks conversion
214
    int                     m_nProblemLevel;
215
    ProblemManager*         m_pProblemManager;
216
    int                     m_iQ;               //index of asked question
633 by cecilios
last work before vacation
217
    wxString                m_sKeyPrefix;
634 by cecilios
starting eBooks conversion
218
219
    //to measure times
220
    wxDateTime              m_tmAsked;      //when was asked last question
627 by cecilios
cleaning and commit recent work
221
222
private:
634 by cecilios
starting eBooks conversion
223
//    void do_stop_sounds();
627 by cecilios
cleaning and commit recent work
224
    void do_display_solution();
225
226
};
227
228
634 by cecilios
starting eBooks conversion
229
//---------------------------------------------------------------------------------------
230
// Abstract class to create exercise to compare scores/sounds
231
class CompareCtrol : public ExerciseCtrol
232
{
233
public:
234
235
    // constructor and destructor
236
    CompareCtrol(long dynId, ApplicationScope& appScope, DocumentWindow* pCanvas);
237
    virtual ~CompareCtrol();
238
239
    enum {
240
        k_num_rows = 1,
241
        k_num_cols = 3,
242
        k_num_buttons = 3,
243
        m_ID_BUTTON = 3010,
244
    };
245
246
247
protected:
248
    //virtual methods implemented in this class
249
    void create_answer_buttons(LUnits height, LUnits spacing);
250
    virtual void initialize_strings();
251
252
protected:
253
    // member variables
254
    ImoButton*       m_pAnswerButton[k_num_buttons];   //buttons for the answers
255
256
};
257
258
259
//---------------------------------------------------------------------------------------
260
// Abstract class to create exercise to compare two scores
639 by cecilios
Fixed error msg in dlg_ear_intervals. Other changes needed for compatibility with lomse changes. Added debug option for drawing spacers.
261
class CompareScoresCtrol : public wxEvtHandler, public CompareCtrol
634 by cecilios
starting eBooks conversion
262
{
263
public:
264
265
    // constructor and destructor
266
    CompareScoresCtrol(long dynId, ApplicationScope& appScope, DocumentWindow* pCanvas);
267
    virtual ~CompareScoresCtrol();
268
269
    //implementation of virtual event handlers
270
    virtual void on_debug_show_source_score();
271
    virtual void on_debug_show_midi_events();
639 by cecilios
Fixed error msg in dlg_ear_intervals. Other changes needed for compatibility with lomse changes. Added debug option for drawing spacers.
272
    virtual void on_end_of_playback();
634 by cecilios
starting eBooks conversion
273
274
protected:
275
    //implementation of some virtual methods
656 by cecilios
initial commit with all changes for 5.1. See changelog
276
    void play(bool fVisualTracking=true);
634 by cecilios
starting eBooks conversion
277
    void PlaySpecificSound(int nButton) {}
278
    void display_solution();
279
    void display_problem_score();
280
    void delete_scores();
281
    void stop_sounds();
282
283
284
protected:
285
    // wxWidgets event handlers
286
    void on_timer_event(wxTimerEvent& WXUNUSED(event));
287
288
    ScorePlayer*    m_pPlayer;
289
    ImoScore*       m_pScore[2];        //the two problem scores
290
    int             m_nNowPlaying;      //score being played (0, 1)
291
    wxTimer         m_oPauseTimer;      //timer to do a pause between the two scores
292
    ImoScore*       m_pSolutionScore;   //solution score
293
    int             m_nPlayMM;          //metronome setting to play the scores
294
    bool            m_fPlayingProblem;  //currently playing the score (might be waiting for timer event)
295
296
private:
656 by cecilios
initial commit with all changes for 5.1. See changelog
297
    void PlayScore(int nIntv, bool fVisualTracking);
634 by cecilios
starting eBooks conversion
298
639 by cecilios
Fixed error msg in dlg_ear_intervals. Other changes needed for compatibility with lomse changes. Added debug option for drawing spacers.
299
    DECLARE_CLASS(CompareScoresCtrol);
300
    //DECLARE_EVENT_TABLE()
634 by cecilios
starting eBooks conversion
301
};
627 by cecilios
cleaning and commit recent work
302
303
//---------------------------------------------------------------------------------------
304
// Abstract class to create exercises with one problem score
305
class OneScoreCtrol : public ExerciseCtrol
306
{
307
protected:
634 by cecilios
starting eBooks conversion
308
    OneScoreCtrol(long dynId, ApplicationScope& appScope, DocumentWindow* pCanvas);
627 by cecilios
cleaning and commit recent work
309
310
public:
311
    virtual ~OneScoreCtrol();
312
313
    //event handlers
634 by cecilios
starting eBooks conversion
314
//    void OnEndOfPlay(lmEndOfPlaybackEvent& WXUNUSED(event));
633 by cecilios
last work before vacation
315
316
    //implementation of virtual event handlers
317
    virtual void on_debug_show_source_score();
318
    virtual void on_debug_show_midi_events();
639 by cecilios
Fixed error msg in dlg_ear_intervals. Other changes needed for compatibility with lomse changes. Added debug option for drawing spacers.
319
    virtual void on_end_of_playback();
627 by cecilios
cleaning and commit recent work
320
321
322
protected:
323
324
    //virtual pure methods defined in this class
325
    virtual void prepare_aux_score(int nButton)=0;
326
327
    //implementation of some virtual methods
656 by cecilios
initial commit with all changes for 5.1. See changelog
328
    virtual void play(bool fVisualTracking=true);
627 by cecilios
cleaning and commit recent work
329
//    void PlaySpecificSound(int nButton);
330
    void display_solution();
634 by cecilios
starting eBooks conversion
331
    void display_problem_score();
627 by cecilios
cleaning and commit recent work
332
    void delete_scores();
333
    void stop_sounds();
334
335
        // member variables
336
337
    ScorePlayer* m_pPlayer;
338
    ImoScore*   m_pProblemScore;    //score with the problem
339
	ImoScore*   m_pSolutionScore;	//if not NULL, score with the solution. If NULL
340
                                    //   problem score will be used as solution score
341
    ImoScore*   m_pAuxScore;        //score to play user selected buttons
342
    int         m_nPlayMM;          //metronome setting to play scores
343
};
344
345
////---------------------------------------------------------------------------------------
346
//// Abstract class to create exercises to compare two Midi pitches
347
//class CompareMidiCtrol : public CompareCtrol
348
//{
349
//public:
634 by cecilios
starting eBooks conversion
350
//    CompareMidiCtrol(long dynId, ApplicationScope& appScope, DocumentCanvas* pCanvas);
627 by cecilios
cleaning and commit recent work
351
//    virtual ~CompareMidiCtrol();
352
//
353
//    // event handlers
354
//    void OnTimerEvent(wxTimerEvent& WXUNUSED(event));
355
//
356
//    //implementation of virtual event handlers
633 by cecilios
last work before vacation
357
//    virtual void on_debug_show_source_score() {}
358
//    virtual void on_debug_show_midi_events() {}
627 by cecilios
cleaning and commit recent work
359
//
360
//protected:
361
//    //implementation of some virtual methods
362
//    virtual void play();
363
//    void PlaySpecificSound(int nButton) {}
364
//    void display_solution();
634 by cecilios
starting eBooks conversion
365
//    void display_problem_score();
627 by cecilios
cleaning and commit recent work
366
//    void delete_scores() {}
367
//    void stop_sounds();
368
//
369
//protected:
370
//    void PlaySound(int iSound);
371
//
372
//
373
//        // member variables
374
//
633 by cecilios
last work before vacation
375
//    MidiPitch            m_mpPitch[2];
627 by cecilios
cleaning and commit recent work
376
//    int                 m_nChannel[2];
377
//    int                 m_nInstr[2];
378
//    long                m_nTimeIntval[2];   //interval between first and second pitch
379
//    bool                m_fStopPrev;        //stop previous pitch when sounding the next pitch
380
//
381
//    wxTimer             m_oTimer;           //timer to control sounds' duration
382
//    int                 m_nNowPlaying;      //pitch number being played or -1
383
//};
384
//
385
//
386
////---------------------------------------------------------------------------------------
387
//// An abstract class for any kind of exercise included in an eBook, that uses
388
//// the full score editor for the exercise
389
//class FullEditorExercise : public wxWindow
390
//{
391
//public:
392
//
393
//    // constructor and destructor
394
//    FullEditorExercise(wxWindow* parent, wxWindowID id,
395
//               ExerciseOptions* pConstrains,
396
//               const wxPoint& pos = wxDefaultPosition,
397
//               const wxSize& size = wxDefaultSize, int style = 0);
398
//
399
//    virtual ~FullEditorExercise();
400
//
401
//    //event handlers
402
//    void OnSize(wxSizeEvent& event);
634 by cecilios
starting eBooks conversion
403
//    void on_settings_button(SpEventInfo pEvent);
633 by cecilios
last work before vacation
404
//    void on_go_back();
634 by cecilios
starting eBooks conversion
405
//    void on_new_problem(SpEventInfo pEvent);
627 by cecilios
cleaning and commit recent work
406
//
407
//protected:
408
//    //IDs for controls
409
//    enum {
410
//        ID_LINK_SETTINGS = 3000,
411
//        ID_LINK_GO_BACK,
412
//        ID_LINK_NEW_PROBLEM,
413
//    };
414
//
415
//    //virtual pure methods to be implemented by derived classes
416
//    virtual void initialize_strings()=0;
417
//    virtual wxDialog* get_settings_dialog()=0;
418
//    virtual void on_settings_changed()=0;
419
//    virtual void set_new_problem()=0;
420
//    virtual lmEditorMode* CreateEditMode() = 0;
421
//
422
//
423
//    //methods invoked from derived classes
424
//    virtual void create_controls();
425
//
426
//
427
//    // member variables
428
//
429
//    ImoScore*            m_pProblemScore;    //score with the problem
430
//    wxBoxSizer*         m_pMainSizer;
633 by cecilios
last work before vacation
431
//    ExerciseOptions*  m_pBaseConstrains;      //constraints for the exercise
627 by cecilios
cleaning and commit recent work
432
//    double              m_rScale;           //current scaling factor
433
//};
434
435
436
}   //namespace lenmus
437
438
#endif  // __LENMUS_EXERCISE_CTROL_H__