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

Implement Note Types #5902

Merged
merged 27 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b205222
Initial Commit
IanCaio Feb 3, 2021
cfb533a
Update Pattern.cpp to account for the Note::Type
IanCaio Feb 3, 2021
a5cf05d
Update PatternView::paintEvent to draw step notes
IanCaio Feb 3, 2021
df88140
Implements StepNotes setting a NPH with 0 frames
IanCaio Feb 3, 2021
7a5ad82
Improves PatternView::paintEvent conditional
IanCaio Feb 3, 2021
725169a
Adds upgrade method for backwards compatibility
IanCaio Feb 3, 2021
faa5209
Addresses Veratil's review
IanCaio Feb 11, 2021
9decf11
Uses ternary expression on statement
IanCaio Feb 11, 2021
3576300
Merge branch 'master' into feature/BBNotes
IanCaio Mar 5, 2021
f5cc889
Merge branch 'master' into feature/BBNotes
IanCaio Apr 18, 2021
1df46a5
Merge branch 'master' into feature/BBNotes
IanCaio Jul 7, 2023
db0d0b7
Addresses PR review (sakertooth)
IanCaio Jul 9, 2023
6b3c75e
Finished changes from review (sakertooth)
IanCaio Jul 9, 2023
4b69615
Uses std::find_if to save codelines
IanCaio Jul 10, 2023
89a62f6
Addresses review from sakertooth
IanCaio Jul 17, 2023
b3511c2
Addresses DomClark's review
IanCaio Jul 23, 2023
dbefa9c
Updates MidiExport to use Note Types
IanCaio Aug 21, 2023
463050a
Merge branch 'master' into feature/BBNotes
IanCaio Aug 28, 2023
0054ece
Fixes ambiguity on enum usage
IanCaio Aug 28, 2023
fe42e97
Merge branch 'master' into feature/BBNotes
IanCaio Oct 17, 2023
38dd8ec
Addresses new code reviews
IanCaio Oct 17, 2023
31a2bd3
Fixes note drawing on Song Editor
IanCaio Oct 17, 2023
43018d7
Adds cassert header to TimePos.cpp
IanCaio Oct 18, 2023
389a245
Apply suggestions from code review
IanCaio Oct 26, 2023
dcb41af
Reverts some changes on MidiExport
IanCaio Nov 3, 2023
2ecadb0
Merge remote-tracking branch 'upstream/master' into feature/BBNotes
IanCaio Nov 18, 2023
67b0b24
Fix the order of included files
IanCaio Nov 18, 2023
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
1 change: 1 addition & 0 deletions data/themes/classic/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ PianoRoll {
qproperty-backgroundShade: rgba( 255, 255, 255, 10 );
qproperty-noteModeColor: rgb( 255, 255, 255 );
qproperty-noteColor: rgb( 119, 199, 216 );
qproperty-stepNoteColor: #9b1313;
qproperty-noteTextColor: rgb( 255, 255, 255 );
qproperty-noteOpacity: 128;
qproperty-noteBorders: true; /* boolean property, set false to have borderless notes */
Expand Down
1 change: 1 addition & 0 deletions data/themes/default/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ PianoRoll {
qproperty-backgroundShade: rgba(255, 255, 255, 10);
qproperty-noteModeColor: #0bd556;
qproperty-noteColor: #0bd556;
qproperty-stepNoteColor: #9b1313;
qproperty-noteTextColor: #ffffff;
qproperty-noteOpacity: 165;
qproperty-noteBorders: false; /* boolean property, set false to have borderless notes */
Expand Down
1 change: 1 addition & 0 deletions include/DataFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class LMMS_EXPORT DataFile : public QDomDocument
void upgrade_1_2_0_rc3();
void upgrade_1_3_0();
void upgrade_noHiddenClipNames();
void upgrade_noteTypes();

// List of all upgrade methods
static const std::vector<UpgradeMethod> UPGRADE_METHODS;
Expand Down
17 changes: 17 additions & 0 deletions include/Note.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ class LMMS_EXPORT Note : public SerializingObject
Note( const Note & note );
virtual ~Note();

// Note types
enum Types
IanCaio marked this conversation as resolved.
Show resolved Hide resolved
{
RegularNote = 0,
StepNote
IanCaio marked this conversation as resolved.
Show resolved Hide resolved
};
typedef Types Type;
IanCaio marked this conversation as resolved.
Show resolved Hide resolved

Type type() const
{
return m_type;
}
void setType(Type t);

// used by GUI
inline void setSelected( const bool selected ) { m_selected = selected; }
inline void setOldKey( const int oldKey ) { m_oldKey = oldKey; }
Expand Down Expand Up @@ -236,6 +250,9 @@ class LMMS_EXPORT Note : public SerializingObject
TimePos m_length;
TimePos m_pos;
DetuningHelper * m_detuning;

// The type of this note
Type m_type;
IanCaio marked this conversation as resolved.
Show resolved Hide resolved
};


Expand Down
2 changes: 2 additions & 0 deletions include/PianoRoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class PianoRoll : public QWidget
Q_PROPERTY(QColor lineColor MEMBER m_lineColor)
Q_PROPERTY(QColor noteModeColor MEMBER m_noteModeColor)
Q_PROPERTY(QColor noteColor MEMBER m_noteColor)
Q_PROPERTY(QColor stepNoteColor MEMBER m_stepNoteColor)
Q_PROPERTY(QColor ghostNoteColor MEMBER m_ghostNoteColor)
Q_PROPERTY(QColor noteTextColor MEMBER m_noteTextColor)
Q_PROPERTY(QColor ghostNoteTextColor MEMBER m_ghostNoteTextColor)
Expand Down Expand Up @@ -419,6 +420,7 @@ protected slots:
QColor m_lineColor;
QColor m_noteModeColor;
QColor m_noteColor;
QColor m_stepNoteColor;
QColor m_noteTextColor;
QColor m_ghostNoteColor;
QColor m_ghostNoteTextColor;
Expand Down
21 changes: 20 additions & 1 deletion src/core/DataFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ const std::vector<DataFile::UpgradeMethod> DataFile::UPGRADE_METHODS = {
&DataFile::upgrade_0_4_0_beta1 , &DataFile::upgrade_0_4_0_rc2,
&DataFile::upgrade_1_0_99 , &DataFile::upgrade_1_1_0,
&DataFile::upgrade_1_1_91 , &DataFile::upgrade_1_2_0_rc3,
&DataFile::upgrade_1_3_0 , &DataFile::upgrade_noHiddenClipNames
&DataFile::upgrade_1_3_0 , &DataFile::upgrade_noHiddenClipNames,
&DataFile::upgrade_noteTypes
};

// Vector of all versions that have upgrade routines.
Expand Down Expand Up @@ -1385,6 +1386,24 @@ void DataFile::upgrade_noHiddenClipNames()
}
}

// Convert the negative length notes to StepNotes
void DataFile::upgrade_noteTypes()
{
QDomNodeList notes = elementsByTagName("note");

for (int i = 0; i < notes.size(); ++i)
{
QDomElement note = notes.item(i).toElement();

int noteSize = note.attribute("len").toInt();
if (noteSize < 0)
{
note.setAttribute("len", DefaultTicksPerBar / 16);
note.setAttribute("type", static_cast<int>(Note::StepNote));
}
}
}

IanCaio marked this conversation as resolved.
Show resolved Hide resolved

void DataFile::upgrade()
{
Expand Down
17 changes: 15 additions & 2 deletions src/core/Note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Note::Note( const TimePos & length, const TimePos & pos,
m_panning( qBound( PanningLeft, panning, PanningRight ) ),
m_length( length ),
m_pos( pos ),
m_detuning( NULL )
m_detuning(nullptr),
m_type(Note::RegularNote)
{
if( detuning )
{
Expand All @@ -71,7 +72,8 @@ Note::Note( const Note & note ) :
m_panning( note.m_panning ),
m_length( note.m_length ),
m_pos( note.m_pos ),
m_detuning( NULL )
m_detuning(nullptr),
IanCaio marked this conversation as resolved.
Show resolved Hide resolved
m_type(note.m_type)
{
if( note.m_detuning )
{
Expand Down Expand Up @@ -136,6 +138,14 @@ void Note::setPanning( panning_t panning )



void Note::setType(Note::Type t)
{
m_type = t;
}




IanCaio marked this conversation as resolved.
Show resolved Hide resolved
TimePos Note::quantized( const TimePos & m, const int qGrid )
{
float p = ( (float) m / qGrid );
Expand Down Expand Up @@ -176,6 +186,7 @@ void Note::saveSettings( QDomDocument & doc, QDomElement & parent )
parent.setAttribute( "pan", m_panning );
parent.setAttribute( "len", m_length );
parent.setAttribute( "pos", m_pos );
parent.setAttribute("type", static_cast<int>(m_type));

if( m_detuning && m_length )
{
Expand All @@ -194,6 +205,8 @@ void Note::loadSettings( const QDomElement & _this )
m_panning = _this.attribute( "pan" ).toInt();
m_length = _this.attribute( "len" ).toInt();
m_pos = _this.attribute( "pos" ).toInt();
// Default m_type value is 0, which corresponds to RegularNote
m_type = static_cast<Type>(_this.attribute("type", "0").toInt());
IanCaio marked this conversation as resolved.
Show resolved Hide resolved

if( _this.hasChildNodes() )
{
Expand Down
10 changes: 5 additions & 5 deletions src/core/TimePos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ tick_t TimePos::getTickWithinBeat( const TimeSig &sig ) const

f_cnt_t TimePos::frames( const float framesPerTick ) const
{
if( m_ticks >= 0 )
{
return static_cast<f_cnt_t>( m_ticks * framesPerTick );
}
return 0;
//TODO: Remove next line, it's just a warning to see
// if any leftover code is still creating notes with
// negative lengths
if (m_ticks < 0) { qWarning("TimePos with negative length"); }
IanCaio marked this conversation as resolved.
Show resolved Hide resolved
return static_cast<f_cnt_t>(m_ticks * framesPerTick);
IanCaio marked this conversation as resolved.
Show resolved Hide resolved
}

double TimePos::getTimeInMilliseconds( bpm_t beatsPerMinute ) const
Expand Down
10 changes: 7 additions & 3 deletions src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3172,11 +3172,15 @@ void PianoRoll::paintEvent(QPaintEvent * pe )
if (note->key() > bottomKey && note->key() <= topKey)
{

// we've done and checked all, let's draw the note
// We've done and checked all, let's draw the note with
// the appropriate color
QColor fillColor = note->type() == Note::RegularNote ? m_noteColor : m_stepNoteColor;
IanCaio marked this conversation as resolved.
Show resolved Hide resolved

drawNoteRect(
p, x + m_whiteKeyWidth, y_base - key * m_keyLineHeight, note_width,
note, m_noteColor, m_noteTextColor, m_selectedNoteColor,
m_noteOpacity, m_noteBorders, drawNoteNames);
note, fillColor, m_noteTextColor, m_selectedNoteColor,
m_noteOpacity, m_noteBorders, drawNoteNames
);
}

// draw note editing stuff
Expand Down
7 changes: 5 additions & 2 deletions src/tracks/InstrumentTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,11 @@ bool InstrumentTrack::play( const TimePos & _start, const fpp_t _frames,
while( nit != notes.end() &&
( cur_note = *nit )->pos() == cur_start )
{
const f_cnt_t note_frames =
cur_note->length().frames( frames_per_tick );
// If the note is a Step Note, frames will be 0 so the NotePlayHandle
// plays for the whole length of the sample
const f_cnt_t note_frames = cur_note->type() == Note::StepNote
IanCaio marked this conversation as resolved.
Show resolved Hide resolved
? 0
: cur_note->length().frames(frames_per_tick);

NotePlayHandle* notePlayHandle = NotePlayHandleManager::acquire( this, _offset, note_frames, *cur_note );
notePlayHandle->setBBTrack( bb_track );
Expand Down
Loading