Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Education
Minuet
Commits
57c2f6f2
Commit
57c2f6f2
authored
Jun 28, 2016
by
Sandro Andrade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Further refactoring on ExerciseController
parent
db92d834
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
52 deletions
+49
-52
src/app/qml/ExerciseView.qml
src/app/qml/ExerciseView.qml
+6
-1
src/app/qml/MinuetMenu.qml
src/app/qml/MinuetMenu.qml
+5
-5
src/interfaces/iexercisecontroller.cpp
src/interfaces/iexercisecontroller.cpp
+4
-1
src/interfaces/iexercisecontroller.h
src/interfaces/iexercisecontroller.h
+20
-1
src/shell/exercisecontroller.cpp
src/shell/exercisecontroller.cpp
+6
-29
src/shell/exercisecontroller.h
src/shell/exercisecontroller.h
+8
-15
No files found.
src/app/qml/ExerciseView.qml
View file @
57c2f6f2
...
...
@@ -109,7 +109,12 @@ Item {
text
:
i18n
(
"
new question
"
)
onClicked
:
{
exerciseView
.
state
=
"
waitingForAnswer
"
chosenExercises
=
exerciseController
.
randomlyChooseExercises
()
exerciseController
.
randomlySelectOptions
()
var
selectedOptions
=
exerciseController
.
selectedOptions
var
newChosenExercises
=
[];
for
(
var
i
=
0
;
i
<
selectedOptions
.
length
;
++
i
)
newChosenExercises
.
push
(
selectedOptions
[
i
].
name
);
chosenExercises
=
newChosenExercises
for
(
var
i
=
0
;
i
<
chosenExercises
.
length
;
++
i
)
for
(
var
j
=
0
;
j
<
answerGrid
.
children
.
length
;
++
j
)
if
(
answerGrid
.
children
[
j
].
children
[
0
].
originalText
==
chosenExercises
[
i
])
{
...
...
src/app/qml/MinuetMenu.qml
View file @
57c2f6f2
...
...
@@ -39,7 +39,7 @@ Item {
function
itemClicked
(
delegateRect
,
index
)
{
var
model
=
delegateRect
.
ListView
.
view
.
model
[
index
].
options
if
(
model
!=
undefined
)
{
exerciseController
.
se
tExercise
Options
(
model
)
exerciseController
.
curren
tExercise
=
model
minuetMenu
.
itemChanged
(
model
)
}
}
...
...
@@ -92,17 +92,17 @@ Item {
stackView
.
push
(
categoryMenu
.
createObject
(
stackView
,
{
model
:
children
}))
var
root
=
delegateRect
.
ListView
.
view
.
model
[
index
].
root
if
(
root
!=
undefined
)
{
exerciseController
.
setM
inRootNote
(
root
.
split
(
'
.
'
)[
0
])
exerciseController
.
setM
axRootNote
(
root
.
split
(
'
.
'
)[
2
])
exerciseController
.
m
inRootNote
=
parseInt
(
root
.
split
(
'
.
'
)[
0
])
exerciseController
.
m
axRootNote
=
parseInt
(
root
.
split
(
'
.
'
)[
2
])
}
var
playMode
=
delegateRect
.
ListView
.
view
.
model
[
index
].
playMode
if
(
playMode
!=
undefined
)
{
if
(
playMode
==
"
scale
"
)
exerciseController
.
setPlayMode
(
0
)
// ScalePlayMode
if
(
playMode
==
"
chord
"
)
exerciseController
.
setPlayMode
(
1
)
// ChordPlayMode
exerciseController
.
setA
nswerLength
(
1
)
exerciseController
.
a
nswerLength
=
1
if
(
playMode
==
"
rhythm
"
)
{
exerciseController
.
setPlayMode
(
2
)
// RhythmPlayMode
exerciseController
.
setA
nswerLength
(
4
)
exerciseController
.
a
nswerLength
=
4
}
}
}
...
...
src/interfaces/iexercisecontroller.cpp
View file @
57c2f6f2
...
...
@@ -26,7 +26,10 @@ namespace Minuet
{
IExerciseController
::
IExerciseController
(
QObject
*
parent
)
:
QObject
(
parent
)
:
QObject
(
parent
),
m_minRootNote
(
0
),
m_maxRootNote
(
0
),
m_answerLength
(
1
)
{
}
...
...
src/interfaces/iexercisecontroller.h
View file @
57c2f6f2
...
...
@@ -24,6 +24,7 @@
#define MINUET_IEXERCISECONTROLLER_H
#include <QtCore/QObject>
#include <QtCore/QJsonArray>
#include "minuetinterfacesexport.h"
...
...
@@ -33,10 +34,28 @@ namespace Minuet
class
MINUETINTERFACES_EXPORT
IExerciseController
:
public
QObject
{
Q_OBJECT
Q_PROPERTY
(
quint8
minRootNote
MEMBER
m_minRootNote
)
Q_PROPERTY
(
quint8
maxRootNote
MEMBER
m_maxRootNote
)
Q_PROPERTY
(
QJsonArray
currentExercise
MEMBER
m_currentExercise
)
Q_PROPERTY
(
quint8
answerLength
MEMBER
m_answerLength
)
Q_PROPERTY
(
QJsonArray
selectedOptions
MEMBER
m_selectedOptions
)
public:
virtual
~
IExerciseController
()
override
;
virtual
QJsonObject
exercises
()
const
=
0
;
public
Q_SLOTS
:
virtual
void
randomlySelectOptions
()
=
0
;
protected:
explicit
IExerciseController
(
QObject
*
parent
=
0
);
~
IExerciseController
()
override
;
quint8
m_minRootNote
;
quint8
m_maxRootNote
;
QJsonArray
m_currentExercise
;
quint8
m_answerLength
;
QJsonArray
m_selectedOptions
;
};
}
...
...
src/shell/exercisecontroller.cpp
View file @
57c2f6f2
...
...
@@ -40,10 +40,7 @@ namespace Minuet
ExerciseController
::
ExerciseController
(
MidiSequencer
*
midiSequencer
)
:
m_midiSequencer
(
midiSequencer
),
m_minRootNote
(
0
),
m_maxRootNote
(
0
),
m_playMode
(
ScalePlayMode
),
m_answerLength
(
1
),
m_chosenRootNote
(
0
)
{
m_exercises
[
"exercises"
]
=
QJsonArray
();
...
...
@@ -68,35 +65,17 @@ bool ExerciseController::initialize()
return
definitionsMerge
&
exercisesMerge
;
}
void
ExerciseController
::
setExerciseOptions
(
QJsonArray
exerciseOptions
)
{
m_exerciseOptions
=
exerciseOptions
;
}
void
ExerciseController
::
setMinRootNote
(
unsigned
int
minRootNote
)
{
m_minRootNote
=
minRootNote
;
}
void
ExerciseController
::
setMaxRootNote
(
unsigned
int
maxRootNote
)
{
m_maxRootNote
=
maxRootNote
;
}
void
ExerciseController
::
setPlayMode
(
PlayMode
playMode
)
{
m_playMode
=
playMode
;
}
void
ExerciseController
::
setAnswerLength
(
unsigned
int
answerLength
)
void
ExerciseController
::
randomlySelectOptions
(
)
{
m_answerLength
=
answerLength
;
}
while
(
!
m_selectedOptions
.
isEmpty
())
m_selectedOptions
.
removeFirst
();
QStringList
ExerciseController
::
randomlyChooseExercises
()
{
qsrand
(
QDateTime
::
currentDateTimeUtc
().
toTime_t
());
QStringList
chosenExercises
;
Song
*
song
=
new
Song
;
song
->
setHeader
(
0
,
1
,
60
);
...
...
@@ -114,8 +93,8 @@ QStringList ExerciseController::randomlyChooseExercises()
}
for
(
unsigned
int
i
=
0
;
i
<
m_answerLength
;
++
i
)
{
unsigned
int
chosenExercise
=
qrand
()
%
m_
exerciseOptions
.
size
();
QString
sequence
=
m_
exerciseOptions
[
chosenExercise
].
toObject
()[
QStringLiteral
(
"sequence"
)].
toString
();
unsigned
int
chosenExercise
=
qrand
()
%
m_
currentExercise
.
size
();
QString
sequence
=
m_
currentExercise
[
chosenExercise
].
toObject
()[
QStringLiteral
(
"sequence"
)].
toString
();
if
(
m_playMode
!=
RhythmPlayMode
)
{
int
minNote
=
INT_MAX
;
...
...
@@ -162,13 +141,11 @@ QStringList ExerciseController::randomlyChooseExercises()
}
}
chosenExercises
<<
m_exerciseOptions
[
chosenExercise
].
toObject
()[
QStringLiteral
(
"name"
)].
toString
(
);
m_selectedOptions
.
append
(
m_currentExercise
[
chosenExercise
]
);
}
if
(
m_playMode
==
RhythmPlayMode
)
{
m_midiSequencer
->
appendEvent
(
m_midiSequencer
->
SMFNoteOn
(
9
,
80
,
120
),
barStart
);
}
return
chosenExercises
;
}
unsigned
int
ExerciseController
::
chosenRootNote
()
...
...
src/shell/exercisecontroller.h
View file @
57c2f6f2
...
...
@@ -25,9 +25,8 @@
#include <interfaces/iexercisecontroller.h>
#include <QJsonArray>
#include <QJsonObject>
#include <QStringList>
#include <QJsonObject>
#include "minuetshellexport.h"
...
...
@@ -53,17 +52,15 @@ public:
RhythmPlayMode
};
Q_INVOKABLE
void
setExerciseOptions
(
QJsonArray
exerciseOptions
);
Q_INVOKABLE
void
setMinRootNote
(
unsigned
int
minRootNote
);
Q_INVOKABLE
void
setMaxRootNote
(
unsigned
int
maxRootNote
);
Q_INVOKABLE
void
setPlayMode
(
PlayMode
playMode
);
Q_INVOKABLE
void
setAnswerLength
(
unsigned
int
answerLength
);
Q_INVOKABLE
QStringList
randomlyChooseExercises
();
Q_INVOKABLE
unsigned
int
chosenRootNote
();
Q_INVOKABLE
void
playChoosenExercise
();
QString
errorString
()
const
;
QJsonObject
exercises
()
const
;
virtual
QJsonObject
exercises
()
const
override
;
public
Q_SLOTS
:
virtual
void
randomlySelectOptions
();
private:
bool
mergeJsonFiles
(
const
QString
directoryName
,
QJsonObject
&
targetObject
,
bool
applyDefinitionsFlag
=
false
,
QString
commonKey
=
""
,
QString
mergeKey
=
""
);
...
...
@@ -78,11 +75,7 @@ private:
MidiSequencer
*
m_midiSequencer
;
QJsonObject
m_exercises
;
QJsonObject
m_definitions
;
QJsonArray
m_exerciseOptions
;
unsigned
int
m_minRootNote
;
unsigned
int
m_maxRootNote
;
PlayMode
m_playMode
;
unsigned
int
m_answerLength
;
unsigned
int
m_chosenRootNote
;
QString
m_errorString
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment