Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editable clefs #332

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,11 +825,20 @@ void CDraw::drawSlot(CSlot* slot)
//int av8Left = slot->getAv8Left();
for (int i=0; i < slot->length(); i++)
{
stavePos.notePos(slot->getSymbol(i).getHand(), slot->getSymbol(i).getNote());
whichPart_t hand = slot->getSymbol(i).getHand();
int clef = PB_SYMBOL_gClef;
if (hand == PB_PART_right) {
clef = m_settings->value("SidePanel/clefRight").toInt();
}
else if (hand == PB_PART_left) {
clef = m_settings->value("SidePanel/clefLeft").toInt();
}
CSymbol symbol = slot->getSymbol(i);
symbol.setClef(clef);
stavePos.notePos(hand, symbol.getNote(), clef);
//ppLogTrace ("compileSlot len %d id %2d next %2d time %2d type %2d note %2d", slot->length(), slot->m_displayListId,
//slot->m_nextDisplayListId, slot->getDeltaTime(), slot->getSymbol(i).getType(), slot->getSymbol(i).getNote());

drawSymbol(slot->getSymbol(i), 0.0, stavePos.getPosYRelative()); // we add this back when drawing this symbol
drawSymbol(symbol, 0.0, stavePos.getPosYRelative()); // we add this back when drawing this symbol
}
}

Expand Down
26 changes: 24 additions & 2 deletions src/GuiSidePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "GuiTopBar.h"
#include "TrackList.h"
#include "Conductor.h"
#include "Draw.h"

GuiSidePanel::GuiSidePanel(QWidget *parent, CSettings* settings)
: QWidget(parent), m_parent(parent)
Expand Down Expand Up @@ -82,7 +83,6 @@ void GuiSidePanel::init(CSong* songObj, CTrackList* trackList, GuiTopBar* topBar

on_rhythmTappingCombo_activated(m_settings->value("SidePanel/rhythmTapping",0).toInt());
rhythmTappingCombo->setCurrentIndex(m_song->cfg_rhythmTapping);

repeatSong->setChecked(m_settings->value("SidePanel/repeatSong",false).toBool());
connect(repeatSong,SIGNAL(stateChanged(int)),this,SLOT(on_repeatSong_released()));

Expand All @@ -105,6 +105,18 @@ void GuiSidePanel::init(CSong* songObj, CTrackList* trackList, GuiTopBar* topBar
connect(act, SIGNAL(triggered()), this, SLOT(clearTrackPart()));

trackListWidget->setContextMenuPolicy(Qt::ActionsContextMenu);

m_settings->setValue("SidePanel/clefRight",PB_SYMBOL_gClef);
m_settings->setValue("SidePanel/clefLeft",PB_SYMBOL_fClef);
clefRightCombo->addItem(tr("Treble"),PB_SYMBOL_gClef);
clefRightCombo->addItem(tr("Bass"),PB_SYMBOL_fClef);
clefLeftCombo->addItem(tr("Treble"),PB_SYMBOL_gClef);
clefLeftCombo->addItem(tr("Bass"),PB_SYMBOL_fClef);
clefRightCombo->setCurrentIndex(0);
clefLeftCombo->setCurrentIndex(1);
trackListWidget->addAction(act);
connect(clefRightCombo, SIGNAL(currentTextChanged(QString)), this, SLOT(on_clefRightComboChange(QString)));
connect(clefLeftCombo, SIGNAL(currentTextChanged(QString)), this, SLOT(on_clefLeftComboChange(QString)));
}

void GuiSidePanel::refresh() {
Expand Down Expand Up @@ -269,13 +281,17 @@ void GuiSidePanel::updateTranslate(){

rhythmTappingCombo->setItemText(0,tr("Drums"));
rhythmTappingCombo->setItemText(1,tr("Melody"));
clefRightCombo->setItemText(0,tr("Treble"));
clefRightCombo->setItemText(1,tr("Bass"));
clefLeftCombo->setItemText(0,tr("Treble"));
clefLeftCombo->setItemText(1,tr("Bass"));

retranslateUi(this);

// --- smart resize panel --- //
int maxDeltaWidth=0;
this->setMaximumWidth(300); // default
QVector<QWidget*> listCheckWidget {label2,listenRadio,rhythmTapRadio,followYouRadio,playAlongRadio,rightHandRadio,bothHandsRadio,leftHandRadio};
QVector<QWidget*> listCheckWidget {label2,listenRadio,rhythmTapRadio,followYouRadio,playAlongRadio,rightHandRadio,bothHandsRadio,leftHandRadio,clefRightCombo,clefLeftCombo};

for (QWidget* w:listCheckWidget){
int delta = 0;
Expand Down Expand Up @@ -313,3 +329,9 @@ void GuiSidePanel::on_rhythmTappingCombo_activated (int index)
autoSetMuteYourPart();
}

void GuiSidePanel::on_clefComboChange (const QString &name, int value)
{
m_settings->setValue(name,value);
CDraw::forceCompileRedraw();
m_song->refreshScroll();
}
19 changes: 19 additions & 0 deletions src/GuiSidePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,25 @@ private slots:

void on_rhythmTappingCombo_activated (int index);

void on_clefComboChange (const QString &name, int value);
void on_clefComboChange (const QString &name, const QString &text)
{
int value = -1;
if (text.toLower() == "treble")
value = PB_SYMBOL_gClef;
else if (text.toLower() == "bass")
value = PB_SYMBOL_fClef;
on_clefComboChange(name, value);
}
void on_clefRightComboChange (const QString &text)
{
on_clefComboChange("SidePanel/clefRight", text);
}
void on_clefLeftComboChange (const QString &text)
{
on_clefComboChange("SidePanel/clefLeft", text);
}

void on_muteYourPartCheck_toggled (bool checked)
{
if (m_song) m_song->mutePianistPart(checked);
Expand Down
28 changes: 28 additions & 0 deletions src/GuiSidePanel.ui
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,34 @@
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="label3">
<property name="text">
<string>Right Hand Clef:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="clefRightCombo"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="label4">
<property name="text">
<string>Left Hand Clef:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="clefLeftCombo"/>
</item>
</layout>
</item>
<item>
<spacer>
<property name="orientation">
Expand Down
10 changes: 8 additions & 2 deletions src/Score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,14 @@ void CScore::drawScore()
glNewList (m_scoreDisplayListId, GL_COMPILE_AND_EXECUTE);
drColor (Cfg::staveColor());

drawSymbol(CSymbol(PB_SYMBOL_gClef, CStavePos(PB_PART_right, -1)), Cfg::clefX()); // The Treble Clef
drawSymbol(CSymbol(PB_SYMBOL_fClef, CStavePos(PB_PART_left, 1)), Cfg::clefX());
if (m_settings->value("SidePanel/clefRight").toInt() == PB_SYMBOL_gClef)
drawSymbol(CSymbol(PB_SYMBOL_gClef, CStavePos(PB_PART_right, -1)), Cfg::clefX()); // The Treble Clef
else if (m_settings->value("SidePanel/clefRight").toInt() == PB_SYMBOL_fClef)
drawSymbol(CSymbol(PB_SYMBOL_fClef, CStavePos(PB_PART_right, 1)), Cfg::clefX());
if (m_settings->value("SidePanel/clefLeft").toInt() == PB_SYMBOL_gClef)
drawSymbol(CSymbol(PB_SYMBOL_gClef, CStavePos(PB_PART_left, -1)), Cfg::clefX());
else if (m_settings->value("SidePanel/clefLeft").toInt() == PB_SYMBOL_fClef)
drawSymbol(CSymbol(PB_SYMBOL_fClef, CStavePos(PB_PART_left, 1)), Cfg::clefX());
drawKeySignature(CStavePos::getKeySignature());
drawStaves(Cfg::staveStartX(), Cfg::scrollStartX());
glEndList ();
Expand Down
14 changes: 10 additions & 4 deletions src/StavePosition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ float CStavePos::m_staveCentralOffset = (staveHeight() * 3)/2;

////////////////////////////////////////////////////////////////////////////////
//! @brief Calculates the position of a note on the stave
void CStavePos::notePos(whichPart_t hand, int midiNote)
void CStavePos::notePos(whichPart_t hand, int midiNote, int clef) // in fact clef is of type musicalSymbol_t but causes circular reference
{
const int notesInAnOctive = 7; // Don't count middle C twice
const int semitonesInAnOctive = 12;
Expand All @@ -48,9 +48,15 @@ void CStavePos::notePos(whichPart_t hand, int midiNote)

lookUpItem = &m_staveLookUpTable[index];

if (m_hand == PB_PART_right)
m_staveIndex = lookUpItem->pianoNote - 7;
else if (m_hand == PB_PART_left)
if (clef == -1) {
if (m_hand == PB_PART_right)
clef = PB_SYMBOL_gClef;
if (m_hand == PB_PART_left)
clef = PB_SYMBOL_fClef;
}
if (m_hand == PB_PART_right && clef == PB_SYMBOL_gClef || m_hand == PB_PART_left && clef == PB_SYMBOL_gClef)
m_staveIndex = lookUpItem->pianoNote - 7;
else if (m_hand == PB_PART_left && clef == PB_SYMBOL_fClef || m_hand == PB_PART_right && clef == PB_SYMBOL_fClef)
m_staveIndex = lookUpItem->pianoNote + 5;

m_staveIndex += (midiNote/semitonesInAnOctive)*notesInAnOctive - notesInAnOctive*5 ;
Expand Down
2 changes: 1 addition & 1 deletion src/StavePosition.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class CStavePos
m_offsetY -= staveCentralOffset();
}

void notePos(whichPart_t hand, int midiNote);
void notePos(whichPart_t hand, int midiNote, int clef = -1); // in fact clef is of type musicalSymbol_t but causes circular reference

////////////////////////////////////////////////////////////////////////////////
//! @brief Sets which stave the note will appear on
Expand Down
9 changes: 7 additions & 2 deletions src/Symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ class CSymbol

////////////////////////////////////////////////////////////////////////////////
//@brief constructors
CSymbol(musicalSymbol_t type, whichPart_t hand, int midiNote)
CSymbol(musicalSymbol_t type, whichPart_t hand, int midiNote, int clef = -1)
{
init();
m_symbolType = type;
m_midiNote = midiNote;
m_hand = hand;
m_midiDuration = 0;
m_stavePos.notePos(hand, midiNote);
m_stavePos.notePos(hand, midiNote, clef);
}

CSymbol()
Expand Down Expand Up @@ -158,6 +158,11 @@ class CSymbol
void setAccidentalModifer(accidentalModifer_t value) {m_accidentalModifer = value;}
accidentalModifer_t getAccidentalModifer() {return m_accidentalModifer;}

void setClef(int clef = -1)
{
m_stavePos.notePos(m_hand, m_midiNote, clef);
}

private:
void init()
{
Expand Down