Skip to content
Snippets Groups Projects
Commit b2c93690 authored by SeeLook's avatar SeeLook
Browse files

Implemented TscoreObject::setNote(), part of TscoreObject::noteClicked() went...

Implemented TscoreObject::setNote(), part of TscoreObject::noteClicked() went there, so using it to set note range in wizard and to change selected note from the instrument
parent c75759b0
No related branches found
No related tags found
No related merge requests found
...@@ -256,6 +256,11 @@ void TnoteObject::setX(qreal xx) { ...@@ -256,6 +256,11 @@ void TnoteObject::setX(qreal xx) {
} }
Trhythm TnoteObject::rhythm() const {
return m_note->rtm;
}
qreal TnoteObject::rightX() const { qreal TnoteObject::rightX() const {
return x() + width() + staff()->gapFactor() * rhythmFactor() - m_alter->width(); return x() + width() + staff()->gapFactor() * rhythmFactor() - m_alter->width();
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "nootkacoreglobal.h" #include "nootkacoreglobal.h"
#include "music/trhythm.h"
#include <QtQuick/qquickitem.h> #include <QtQuick/qquickitem.h>
...@@ -70,6 +71,8 @@ public: ...@@ -70,6 +71,8 @@ public:
qreal notePosY() const { return m_notePosY; } qreal notePosY() const { return m_notePosY; }
Q_INVOKABLE Trhythm rhythm() const;
/** /**
* Note number in the staff * Note number in the staff
*/ */
......
...@@ -282,10 +282,66 @@ CHECKTIME ( ...@@ -282,10 +282,66 @@ CHECKTIME (
} }
void TscoreObject::setNote(int staffNr, int noteNr, const Tnote& n) { void TscoreObject::setNote(TnoteObject* no, const Tnote& n) {
if (staffNr < 0 || staffNr >= m_staves.count()) { if (no) {
qDebug() << "[TscoreObject] There is no staff number" << staffNr; auto oldNote = *no->wrapper()->note();
return; auto newNote = n;
newNote.rtm.setBeam(oldNote.rtm.beam()); // TODO as long as we don't change rhythm
newNote.rtm.setTie(oldNote.rtm.tie()); // TODO as long as we don't change rhythm
bool fitStaff = false;
// disconnect tie (if any) if note pitch changed
QPoint notesForAlterCheck;// x is first note and y is the last note to check
if (oldNote.rtm.tie() && newNote.chromatic() != oldNote.chromatic()) {
// alters of notes has to be checked due to note changed
// and all measures contained note with the tie are affected. Find them then
notesForAlterCheck = tieRange(no);
notesForAlterCheck.setX(m_segments[notesForAlterCheck.x()]->item()->measure()->firstNoteId());
notesForAlterCheck.setY(m_segments[notesForAlterCheck.y()]->item()->measure()->lastNoteId());
if (oldNote.rtm.tie() == Trhythm::e_tieStart) {
m_segments[no->index() + 1]->disconnectTie(TnotePair::e_untieNext);
} else { // tie continue or end
if (oldNote.rtm.tie() == Trhythm::e_tieCont)
m_segments[no->index() + 1]->disconnectTie(TnotePair::e_untieNext);
m_segments[no->index() - 1]->disconnectTie(TnotePair::e_untiePrev);
}
newNote.rtm.setTie(Trhythm::e_noTie);
if (no->wrapper() == no->staff()->firstNote())
no->staff()->deleteExtraTie();
fitStaff = true;
}
no->wrapper()->setNote(newNote);
// When note or alter are different - check accidentals in whole measure and fit staff if necessary
if (!notesForAlterCheck.isNull() || oldNote.note != newNote.note || oldNote.alter != newNote.alter) {
if (notesForAlterCheck.isNull())
notesForAlterCheck = QPoint(no->measure()->firstNoteId(), no->measure()->lastNoteId());
auto measureToRefresh = m_segments[notesForAlterCheck.x()]->item()->measure();
for (int n = notesForAlterCheck.x(); n <= notesForAlterCheck.y(); ++n) {
if (m_segments[n]->note()->note == oldNote.note || m_segments[n]->note()->note == newNote.note) {
fitStaff = true;
m_segments[n]->item()->updateAlter();
}
// Update measure sums (notes width)
if (m_segments[n]->item()->measure() != measureToRefresh) {
measureToRefresh->refresh();
measureToRefresh = m_segments[n]->item()->measure();
}
}
measureToRefresh->refresh();
}
// update note range on current staff
if (oldNote.note != newNote.note || oldNote.octave != newNote.octave)
no->staff()->checkNotesRange();
// If there is a beam - prepare it again then draw
if (no->wrapper()->beam()) {
no->wrapper()->beam()->prepareBeam();
if (!fitStaff)
no->wrapper()->beam()->drawBeam();
}
if (fitStaff) {
m_segments[notesForAlterCheck.x()]->item()->staff()->fit();
if (m_segments[notesForAlterCheck.y()]->item()->staff() != m_segments[notesForAlterCheck.x()]->item()->staff())
m_segments[notesForAlterCheck.y()]->item()->staff()->fit();
}
} }
} }
...@@ -308,63 +364,9 @@ void TscoreObject::noteClicked(qreal yPos) { ...@@ -308,63 +364,9 @@ void TscoreObject::noteClicked(qreal yPos) {
static_cast<char>(m_cursorAlter), newRhythm); static_cast<char>(m_cursorAlter), newRhythm);
if (m_workRhythm->isRest() || m_clefType == Tclef::NoClef) if (m_workRhythm->isRest() || m_clefType == Tclef::NoClef)
newNote.note = 0; newNote.note = 0;
Tnote oldNote = *activeNote()->wrapper()->note();
newNote.rtm.setBeam(oldNote.rtm.beam()); // TODO as long as we don't change rhythm setNote(m_activeNote, newNote);
newNote.rtm.setTie(oldNote.rtm.tie()); // TODO as long as we don't change rhythm
bool fitStaff = false;
// disconnect tie (if any) if note pitch changed
QPoint notesForAlterCheck;// x is first note and y is the last note to check
if (oldNote.rtm.tie() && newNote.chromatic() != oldNote.chromatic()) {
// alters of notes has to be checked due to note changed
// and all measures contained note with the tie are affected. Find them then
notesForAlterCheck = tieRange(activeNote());
notesForAlterCheck.setX(m_segments[notesForAlterCheck.x()]->item()->measure()->firstNoteId());
notesForAlterCheck.setY(m_segments[notesForAlterCheck.y()]->item()->measure()->lastNoteId());
if (oldNote.rtm.tie() == Trhythm::e_tieStart) {
m_segments[activeNote()->index() + 1]->disconnectTie(TnotePair::e_untieNext);
} else { // tie continue or end
if (oldNote.rtm.tie() == Trhythm::e_tieCont)
m_segments[activeNote()->index() + 1]->disconnectTie(TnotePair::e_untieNext);
m_segments[activeNote()->index() - 1]->disconnectTie(TnotePair::e_untiePrev);
}
newNote.rtm.setTie(Trhythm::e_noTie);
if (activeNote()->wrapper() == activeNote()->staff()->firstNote())
activeNote()->staff()->deleteExtraTie();
fitStaff = true;
}
activeNote()->wrapper()->setNote(newNote);
// When note or alter are different - check accidentals in whole measure and fit staff if necessary
if (!notesForAlterCheck.isNull() || oldNote.note != newNote.note || oldNote.alter != newNote.alter) {
if (notesForAlterCheck.isNull())
notesForAlterCheck = QPoint(activeNote()->measure()->firstNoteId(), activeNote()->measure()->lastNoteId());
auto measureToRefresh = m_segments[notesForAlterCheck.x()]->item()->measure();
for (int n = notesForAlterCheck.x(); n <= notesForAlterCheck.y(); ++n) {
if (m_segments[n]->note()->note == oldNote.note || m_segments[n]->note()->note == newNote.note) {
fitStaff = true;
m_segments[n]->item()->updateAlter();
}
// Update measure sums (notes width)
if (m_segments[n]->item()->measure() != measureToRefresh) {
measureToRefresh->refresh();
measureToRefresh = m_segments[n]->item()->measure();
}
}
measureToRefresh->refresh();
}
// update note range on current staff
if (oldNote.note != newNote.note || oldNote.octave != newNote.octave)
activeNote()->staff()->checkNotesRange();
// If there is a beam - prepare it again then draw
if (activeNote()->wrapper()->beam()) {
activeNote()->wrapper()->beam()->prepareBeam();
if (!fitStaff)
activeNote()->wrapper()->beam()->drawBeam();
}
if (fitStaff) {
m_segments[notesForAlterCheck.x()]->item()->staff()->fit();
if (m_segments[notesForAlterCheck.y()]->item()->staff() != m_segments[notesForAlterCheck.x()]->item()->staff())
m_segments[notesForAlterCheck.y()]->item()->staff()->fit();
}
emit clicked(); emit clicked();
} }
......
...@@ -113,7 +113,7 @@ public: ...@@ -113,7 +113,7 @@ public:
void setKeySignature(int k); void setKeySignature(int k);
Q_INVOKABLE void addNote(const Tnote& n); Q_INVOKABLE void addNote(const Tnote& n);
Q_INVOKABLE void setNote(int staffNr, int noteNr, const Tnote& n); Q_INVOKABLE void setNote(TnoteObject* no, const Tnote& n);
/** /**
* Returns a note item of @p TnoteObject * Returns a note item of @p TnoteObject
......
...@@ -79,7 +79,11 @@ ApplicationWindow { ...@@ -79,7 +79,11 @@ ApplicationWindow {
id: instrument id: instrument
z: 1 z: 1
onNote: { onNote: {
score.addNote(Noo.note(n, score.workRhythm)) var cn = score.currentNote
if (cn)
score.setNote(cn, Noo.note(n, cn.rhythm()))
else
score.addNote(Noo.note(n, score.workRhythm))
} }
} }
} }
...@@ -88,7 +92,6 @@ ApplicationWindow { ...@@ -88,7 +92,6 @@ ApplicationWindow {
function randNotes() { function randNotes() {
var rest = (Math.random() * 100) > 90 var rest = (Math.random() * 100) > 90
// var accid = rest ? 0 : Math.min(Math.max(-2, -3 + Math.random() * 6), 2)
var accid = rest ? 0 : Math.min(Math.floor(Math.random() * 2), 1) var accid = rest ? 0 : Math.min(Math.floor(Math.random() * 2), 1)
var note = rest ? 0 : 1 + Math.random() * 7 var note = rest ? 0 : 1 + Math.random() * 7
var octave = -2 + Math.random() * 5 var octave = -2 + Math.random() * 5
......
...@@ -22,9 +22,8 @@ ToolBar { ...@@ -22,9 +22,8 @@ ToolBar {
HeadButton { action: nootkaWindow.examAct } HeadButton { action: nootkaWindow.examAct }
} }
PitchView { PitchView {
x: lab.x - parent.width * 0.41 x: lab.x - parent.width * 0.41; y: parent.height * 0.05
id: pitchView height: parent.height * 0.9
height: parent.height
width: parent.width * 0.4 width: parent.width * 0.4
} }
NootkaLabel { NootkaLabel {
......
...@@ -117,7 +117,7 @@ Flickable { ...@@ -117,7 +117,7 @@ Flickable {
id: addComp id: addComp
NoteAdd { NoteAdd {
noteText: rtmControl ? rtmControl.rhythmText : "z" noteText: rtmControl ? rtmControl.rhythmText : "z"
onAdd: score.addNote(scoreObj.posToNote(yPos)) onAdd: { score.addNote(scoreObj.posToNote(yPos)); currentNote = null }
alterText: accidControl.text alterText: accidControl.text
} }
} }
...@@ -172,5 +172,5 @@ Flickable { ...@@ -172,5 +172,5 @@ Flickable {
noteAdd.lastNote = lastNote noteAdd.lastNote = lastNote
} }
function setNote(staff, nr, n) { scoreObj.setNote(staff, nr, n) } function setNote(noteItem, note) { scoreObj.setNote(noteItem, note) }
} }
...@@ -11,18 +11,18 @@ import "../" ...@@ -11,18 +11,18 @@ import "../"
Flickable { Flickable {
clip: true clip: true
contentHeight: clefCol.height contentHeight: mainItem.height
contentWidth: width contentWidth: width
Item { Item {
id: clefCol id: mainItem
width: parent.width; height: childrenRect.height width: parent.width; height: childrenRect.height
Loader { sourceComponent: nootkaWindow.instrument === 0 ? noInstrComp : null } Loader { sourceComponent: nootkaWindow.instrument === 0 ? noInstrComp : null }
Component { Component {
id: noInstrComp id: noInstrComp
Column { Column {
parent: clefCol parent: mainItem
width: parent ? parent.width : 0 width: parent ? parent.width : 0
spacing: nootkaWindow.fontSize spacing: nootkaWindow.fontSize
Text { Text {
...@@ -46,8 +46,9 @@ Flickable { ...@@ -46,8 +46,9 @@ Flickable {
addNote(scoreObj.highestNote()) addNote(scoreObj.highestNote())
} }
onClefChanged: { onClefChanged: {
// sc.addNote(scoreObj.lowestNote()) scoreObj.clefType = clef
// sc.addNote(scoreObj.highestNote()) setNote(scoreObj.note(0), scoreObj.lowestNote())
setNote(scoreObj.note(1), scoreObj.highestNote())
} }
} }
} }
...@@ -58,7 +59,7 @@ Flickable { ...@@ -58,7 +59,7 @@ Flickable {
Component { Component {
id: classicComp id: classicComp
Column { Column {
parent: clefCol parent: mainItem
spacing: nootkaWindow.fontSize spacing: nootkaWindow.fontSize
width: parent ? parent.width : 0 width: parent ? parent.width : 0
Text { Text {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment