-
Notifications
You must be signed in to change notification settings - Fork 8
/
Morse.h
168 lines (129 loc) · 4.58 KB
/
Morse.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#ifndef MORSE_H
#define MORSE_H
#include <QtCore/QString>
#include <QtMultimedia/QAudioOutput>
#include <QtCore/QMap>
#include <QtCore/QList>
#include <QLabel>
#include <QtCore/QTime>
#include <QtCore/QTimer>
#include <QTextCursor>
#include <QIcon>
#include <QAudioSink>
#include <QtCore/QSignalMapper>
#include "Generator.h"
#include "MorseStat.h"
#include "modes/MorseMode.h"
#include "ui_MainWindow.h"
#include "ui_AboutDialog.h"
class MainWindow;
class PlayMode;
class MorseMode;
class Morse : public QObject
{
public:
Q_OBJECT
public:
Morse();
Morse(MainWindow *parent, QAudioSink *output, Ui::MainWindow *ui);
static const int DEFAULT_TONE = 700;
enum ditdah{ DIT, DAH, SPACE, PAUSE };
enum TrainingMode { FRONTPAGE, PLAY, TRAIN, SPEEDTRAIN, WORDS, GROUPS, KEYING, WORDGAME, GROUPGAME, READ, KEYINVADERS, // eventually: TEST
TM_FIRST = FRONTPAGE, TM_LAST = KEYINVADERS };
static const int maximumTrainingMode = READ;
enum AudioMode { STOPPED, PLAYING, PAUSED };
enum BadLetterWeighting { LOW = 1, HIGH = 2 };
void setupWidgets();
void setupTopButtons(QLayout *parentLayout);
void createModesMenuButton(QPushButton *modeButton);
void createModesMenu(QMenu *modeButton);
void setupSequenceLayouts(QVBoxLayout *parentLayout, QWidget *theMainThing);
void setupWPMLayout(QVBoxLayout *parentLayout, QWidget *theMainThing);
void setupConnections();
MorseMode * getMode(TrainingMode) const;
void setupWords();
void setupSequences();
void clearList();
void createTones(int wpm, int spacewpm = -1, int letterspacewpm = -1);
void createTones(float ditSecsF, int dahMult = 3, int pauseMult = 1, int letterPauseMult = 3, int spaceMult = 7);
void createSpacedTones(float ditSecsF, float spaceSecsF, float letterSpaceSecs);
void add(Generator *nextsound);
void add(QChar c, bool addpause = true);
void add(const QString &textToAdd);
QTime addAndPlayIt(QChar c);
QTime playIt(QChar c, bool addLeadInPause = true);
QTime sequenceTime();
const QList<ditdah> *getLetterCode(QChar letter) const;
MorseStat *getStat(const QChar &key);
void handleKeyResponse(QChar letterPressed);
bool enterPressed();
Generator *dit();
Generator *dah();
Generator *pause();
Generator *letterPause();
Generator *space();
float ditSecsF();
float dahSecsF();
float pauseSecsF();
float letterPauseSecsF();
float spaceSecsF();
int ditSecsMS();
int dahSecsMS();
int pauseSecsMS();
int letterPauseSecsMS();
int spaceSecsMS();
int currentWPMGoal();
int currentWPMAccept();
int tone();
void setWPMGoal(int wpmGoal);
void setWPMAccept(int wpmAccept);
void setTone(int tone);
AudioMode audioMode();
void setAudioMode(AudioMode newmode);
TrainingMode trainingMode();
BadLetterWeighting badLetterWeighting();
MainWindow *parent();
public slots:
void playSequence();
QTime maybePlaySequence(bool addPause = false);
void generatorDone();
void audioFinished(QAudio::State state);
void keyPressed(QString newtext);
void keyPressed(QChar key);
void keyReleased(QString newtext);
void keyReleased(QChar key);
void goHome();
void help();
void prefsButton();
void aboutButton();
void switchMode(int newMode);
void clearStatsButton();
void playButton();
void saveSettings();
void loadSettings();
void pauseAudio();
void playAudio();
public:
QMap<QChar, QList<ditdah> *> code;
QMenuBar * menuBar();
private:
void _createTones();
QMap<TrainingMode, MorseMode *> m_modes;
MainWindow *m_parent;
QAudioSink *m_audioOutput;
float m_ditSecs, m_dahSecs, m_pauseSecs, m_letterPauseSecs, m_spaceSecs;
int m_dahMult, m_pauseMult, m_letterPauseMult, m_spaceMult;
Generator *m_dit, *m_dah, *m_space, *m_pause, *m_letterPause;
Generator *m_playBuffer;
AudioMode m_playingMode;
TrainingMode m_gameMode;
int m_currentWPMGoal;
int m_currentWPMAccept;
Ui::MainWindow *m_ui;
BadLetterWeighting m_badLetterWeighting;
QTimer m_timer;
int m_tone;
QTime m_leadInPause;
QSignalMapper *m_signalMapper;
};
#endif // MORSE_H