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

Start to add quintuplet, septuplet and 9-tuplet support. #364

Closed
wants to merge 1 commit into from
Closed
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
37 changes: 37 additions & 0 deletions src/core/include/hydrogen/Preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,15 @@ class Preferences : public H2Core::Object
bool isPatternEditorUsingTriplets();
void setPatternEditorUsingTriplets( bool value );

bool isPatternEditorUsingQuintuplets();
void setPatternEditorUsingQuintuplets( bool value );

bool isPatternEditorUsingSeptuplets();
void setPatternEditorUsingSeptuplets( bool value );

bool isPatternEditorUsing9tuplets();
void setPatternEditorUsing9tuplets( bool value );

bool isFXTabVisible();
void setFXTabVisible( bool value );

Expand Down Expand Up @@ -472,6 +481,9 @@ class Preferences : public H2Core::Object
float mixerFalloffSpeed;
int m_nPatternEditorGridResolution;
bool m_bPatternEditorUsingTriplets;
bool m_bPatternEditorUsingQuintuplets;
bool m_bPatternEditorUsingSeptuplets;
bool m_bPatternEditorUsing9tuplets;
bool m_bShowInstrumentPeaks;
bool m_bIsFXTabVisible;
bool m_bUseRelativeFilenamesForPlaylists;
Expand Down Expand Up @@ -721,13 +733,38 @@ inline void Preferences::setPatternEditorGridResolution( int value ) {
m_nPatternEditorGridResolution = value;
}

inline bool Preferences::isPatternEditorUsingQuintuplets() {
return m_bPatternEditorUsingQuintuplets;
}

inline bool Preferences::isPatternEditorUsingSeptuplets() {
return m_bPatternEditorUsingSeptuplets;
}

inline bool Preferences::isPatternEditorUsing9tuplets() {
return m_bPatternEditorUsing9tuplets;
}

inline bool Preferences::isPatternEditorUsingTriplets() {
return m_bPatternEditorUsingTriplets;
}

inline void Preferences::setPatternEditorUsingTriplets( bool value ) {
m_bPatternEditorUsingTriplets = value;
}

inline void Preferences::setPatternEditorUsingQuintuplets( bool value ) {
m_bPatternEditorUsingQuintuplets = value;
}

inline void Preferences::setPatternEditorUsingSeptuplets( bool value ) {
m_bPatternEditorUsingSeptuplets = value;
}

inline void Preferences::setPatternEditorUsing9tuplets( bool value ) {
m_bPatternEditorUsing9tuplets = value;
}

inline bool Preferences::isFXTabVisible() {
return m_bIsFXTabVisible;
}
Expand Down
12 changes: 11 additions & 1 deletion src/core/src/hydrogen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1836,7 +1836,17 @@ void Hydrogen::addRealtimeNote( int instrument,
Preferences *pref = Preferences::get_instance();
unsigned int realcolumn = 0;
unsigned res = pref->getPatternEditorGridResolution();
int nBase = pref->isPatternEditorUsingTriplets() ? 3 : 4;
int nBase;
if(pref->isPatternEditorUsingTriplets())
nBase = 3;
else if(pref->isPatternEditorUsingQuintuplets())
nBase = 5;
else if(pref->isPatternEditorUsingSeptuplets())
nBase = 7;
else if(pref->isPatternEditorUsing9tuplets())
nBase = 9;
else
nBase = 4;
int scalar = ( 4 * MAX_NOTES ) / ( res * nBase );
bool hearnote = forcePlay;
int currentPatternNumber;
Expand Down
44 changes: 41 additions & 3 deletions src/gui/src/PatternEditor/DrumPatternEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ DrumPatternEditor::DrumPatternEditor(QWidget* parent, PatternEditorPanel *panel)
, Object( __class_name )
, m_nResolution( 8 )
, m_bUseTriplets( false )
, m_bUseQuintuplets( false )
, m_bUseSeptuplets( false )
, m_bUse9tuplets( false )
, m_bRightBtnPressed( false )
, m_pDraggedNote( NULL )
, m_pPattern( NULL )
Expand Down Expand Up @@ -129,6 +132,15 @@ int DrumPatternEditor::getColumn(QMouseEvent *ev)
if (m_bUseTriplets) {
nBase = 3;
}
else if (m_bUseQuintuplets) {
nBase = 5;
}
else if (m_bUseSeptuplets) {
nBase = 7;
}
else if (m_bUse9tuplets) {
nBase = 9;
}
else {
nBase = 4;
}
Expand Down Expand Up @@ -646,6 +658,15 @@ void DrumPatternEditor::__draw_grid( QPainter& p )
if (m_bUseTriplets) {
nBase = 3;
}
else if (m_bUseQuintuplets) {
nBase = 5;
}
else if (m_bUseSeptuplets) {
nBase = 7;
}
else if (m_bUse9tuplets) {
nBase = 9;
}
else {
nBase = 4;
}
Expand All @@ -660,7 +681,7 @@ void DrumPatternEditor::__draw_grid( QPainter& p )
if ( m_pPattern ) {
nNotes = m_pPattern->get_length();
}
if (!m_bUseTriplets) {
if (!m_bUseTriplets && !m_bUseQuintuplets && !m_bUseSeptuplets && !m_bUse9tuplets) {
for ( int i = 0; i < nNotes + 1; i++ ) {
uint x = 20 + i * m_nGridWidth;

Expand Down Expand Up @@ -700,11 +721,25 @@ void DrumPatternEditor::__draw_grid( QPainter& p )
uint nCounter = 0;
int nSize = 4 * MAX_NOTES / (nBase * m_nResolution);

int tuplet_size;
if(m_bUseTriplets) {
tuplet_size = 3;
}
else if (m_bUseQuintuplets) {
tuplet_size = 5;
}
else if (m_bUseSeptuplets) {
tuplet_size = 7;
}
else if (m_bUse9tuplets) {
tuplet_size = 9;
}

for ( int i = 0; i < nNotes + 1; i++ ) {
uint x = 20 + i * m_nGridWidth;

if ( (i % nSize) == 0) {
if ((nCounter % 3) == 0) {
if ((nCounter % tuplet_size) == 0) {
p.setPen( QPen( res_1, 0 ) );
}
else {
Expand Down Expand Up @@ -806,10 +841,13 @@ void DrumPatternEditor::hideEvent ( QHideEvent *ev )



void DrumPatternEditor::setResolution(uint res, bool bUseTriplets)
void DrumPatternEditor::setResolution(uint res, bool bUseTriplets, bool bUseQuintuplets, bool bUseSeptuplets, bool bUse9tuplets)
{
this->m_nResolution = res;
this->m_bUseTriplets = bUseTriplets;
this->m_bUseQuintuplets = bUseQuintuplets;
this->m_bUseSeptuplets = bUseSeptuplets;
this->m_bUse9tuplets = bUse9tuplets;

// redraw all
update( 0, 0, width(), height() );
Expand Down
8 changes: 7 additions & 1 deletion src/gui/src/PatternEditor/DrumPatternEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ class DrumPatternEditor : public QWidget, public EventListener, public H2Core::O
DrumPatternEditor(QWidget* parent, PatternEditorPanel *panel);
~DrumPatternEditor();

void setResolution(uint res, bool bUseTriplets);
void setResolution(uint res, bool bUseTriplets, bool bUseQuintuplets, bool bUseSeptuplets, bool bUse9tuplets);
uint getResolution() { return m_nResolution; }
bool isUsingTriplets() { return m_bUseTriplets; }
bool isUsingQuintuplets() { return m_bUseQuintuplets; }
bool isUsingSeptuplets() { return m_bUseSeptuplets; }
bool isUsing9tuplets() { return m_bUse9tuplets; }

void zoom_in();
void zoom_out();
Expand Down Expand Up @@ -113,6 +116,9 @@ class DrumPatternEditor : public QWidget, public EventListener, public H2Core::O
int m_nEditorHeight;
uint m_nResolution;
bool m_bUseTriplets;
bool m_bUseQuintuplets;
bool m_bUseSeptuplets;
bool m_bUse9tuplets;

bool m_bRightBtnPressed;
H2Core::Note *m_pDraggedNote;
Expand Down
112 changes: 109 additions & 3 deletions src/gui/src/PatternEditor/PatternEditorPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ PatternEditorPanel::PatternEditorPanel( QWidget *pParent )
__resolution_combo->addItem( "16T" );
__resolution_combo->addItem( "32T" );
__resolution_combo->addSeparator();
__resolution_combo->addItem("2Q");
__resolution_combo->addItem("4Q");
__resolution_combo->addItem("8Q");
__resolution_combo->addItem("16Q");
__resolution_combo->addSeparator();
__resolution_combo->addItem("8S");
__resolution_combo->addItem("16S");
__resolution_combo->addSeparator();
__resolution_combo->addItem("8N");
__resolution_combo->addItem("16N");
__resolution_combo->addSeparator();
__resolution_combo->addItem( "off" );
__resolution_combo->update();
__resolution_combo->move( 121, 2 );
Expand Down Expand Up @@ -463,7 +474,10 @@ PatternEditorPanel::PatternEditorPanel( QWidget *pParent )

// restore grid resolution
int nIndex;
if ( pPref->isPatternEditorUsingTriplets() == false ) {
if ( pPref->isPatternEditorUsingTriplets() == false
&& pPref->isPatternEditorUsingQuintuplets() == false
&& pPref->isPatternEditorUsingSeptuplets() == false
&& pPref->isPatternEditorUsing9tuplets() == false) {
switch ( pPref->getPatternEditorGridResolution() ) {
case 4:
__resolution_combo->set_text( "4" );
Expand Down Expand Up @@ -496,7 +510,7 @@ PatternEditorPanel::PatternEditorPanel( QWidget *pParent )
nIndex = 0;
}
}
else {
else if ( pPref->isPatternEditorUsingTriplets() ){
switch ( pPref->getPatternEditorGridResolution() ) {
case 8:
__resolution_combo->set_text( "4T" );
Expand Down Expand Up @@ -524,6 +538,74 @@ PatternEditorPanel::PatternEditorPanel( QWidget *pParent )
nIndex = 5;
}
}

else if ( pPref->isPatternEditorUsingQuintuplets() ){
switch ( pPref->getPatternEditorGridResolution() ) {
case 4:
__resolution_combo->set_text( "2Q" );
nIndex = 9;
break;

case 8:
__resolution_combo->set_text( "4Q" );
nIndex = 10;
break;

case 16:
__resolution_combo->set_text( "8Q" );
nIndex = 11;
break;

case 32:
__resolution_combo->set_text( "16Q" );
nIndex = 12;
break;

default:
ERRORLOG( QString("Wrong grid resolution: %1").arg( pPref->getPatternEditorGridResolution() ) );
__resolution_combo->set_text( "4Q" );
nIndex = 10;
}
}

else if ( pPref->isPatternEditorUsingSeptuplets() ){
switch ( pPref->getPatternEditorGridResolution() ) {
case 16:
__resolution_combo->set_text( "8S" );
nIndex = 13;
break;

case 32:
__resolution_combo->set_text( "16S" );
nIndex = 14;
break;

default:
ERRORLOG( QString("Wrong grid resolution: %1").arg( pPref->getPatternEditorGridResolution() ) );
__resolution_combo->set_text( "8S" );
nIndex = 13;
}
}

else if ( pPref->isPatternEditorUsing9tuplets() ){
switch ( pPref->getPatternEditorGridResolution() ) {
case 16:
__resolution_combo->set_text( "8N" );
nIndex = 15;
break;

case 32:
__resolution_combo->set_text( "16N" );
nIndex = 16;
break;

default:
ERRORLOG( QString("Wrong grid resolution: %1").arg( pPref->getPatternEditorGridResolution() ) );
__resolution_combo->set_text( "8N" );
nIndex = 15;
}
}

gridResolutionChanged(__resolution_combo->getText());

//set pre delete
Expand Down Expand Up @@ -600,10 +682,31 @@ void PatternEditorPanel::gridResolutionChanged( QString str )
{
int nResolution;
bool bUseTriplets = false;
bool bUseQuintuplets = false;
bool bUseSeptuplets = false;
bool bUse9tuplets = false;

if ( str.contains( "off" ) ) {
nResolution=MAX_NOTES;
}
else if ( str.contains( "Q" ) ) {
bUseQuintuplets = true;
QString temp = str;
temp.chop( 1 );
nResolution = temp.toInt() * 2;
}
else if ( str.contains( "S" ) ) {
bUseSeptuplets = true;
QString temp = str;
temp.chop( 1 );
nResolution = temp.toInt() * 2;
}
else if ( str.contains( "N" ) ) {
bUse9tuplets = true;
QString temp = str;
temp.chop( 1 );
nResolution = temp.toInt() * 2;
}
else if ( str.contains( "T" ) ) {
bUseTriplets = true;
QString temp = str;
Expand All @@ -615,11 +718,14 @@ void PatternEditorPanel::gridResolutionChanged( QString str )
}

//INFOLOG( to_string( nResolution ) );
m_pDrumPatternEditor->setResolution( nResolution, bUseTriplets );
m_pDrumPatternEditor->setResolution( nResolution, bUseTriplets, bUseQuintuplets, bUseSeptuplets, bUse9tuplets );
m_pPianoRollEditor->setResolution( nResolution, bUseTriplets );

Preferences::get_instance()->setPatternEditorGridResolution( nResolution );
Preferences::get_instance()->setPatternEditorUsingTriplets( bUseTriplets );
Preferences::get_instance()->setPatternEditorUsingQuintuplets( bUseQuintuplets );
Preferences::get_instance()->setPatternEditorUsingSeptuplets( bUseSeptuplets );
Preferences::get_instance()->setPatternEditorUsing9tuplets( bUse9tuplets );
}


Expand Down