diff --git a/include/InstrumentTrack.h b/include/InstrumentTrack.h index 29348b98eb6..c6d5b61a8d6 100644 --- a/include/InstrumentTrack.h +++ b/include/InstrumentTrack.h @@ -108,6 +108,11 @@ class LMMS_EXPORT InstrumentTrack : public Track, public MidiEventProcessor return m_instrument; } + f_cnt_t envFrames() + { + return m_soundShaping.envFrames(); + } + void deleteNotePluginData( NotePlayHandle * _n ); // name-stuff diff --git a/include/Pattern.h b/include/Pattern.h index 5192da9faf8..a8e2b3e18bf 100644 --- a/include/Pattern.h +++ b/include/Pattern.h @@ -132,6 +132,7 @@ protected slots: void setType( PatternTypes _new_pattern_type ); void checkType(); + void adjustSteps(); void resizeToFirstTrack(); diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 2f948523abc..aac1fa5ec15 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -4126,6 +4126,15 @@ void PianoRoll::pasteNotes() cur_note.restoreState( list.item( i ).toElement() ); cur_note.setPos( cur_note.pos() + Note::quantized( m_timeLine->pos(), quantization() ) ); + if ((cur_note.length().getTicks() == -DefaultTicksPerBar) && (m_pattern->type() != Pattern::BeatPattern)) + { + // the length of copied notes is set to the length of the instruments envelope + f_cnt_t envFrames = m_pattern->instrumentTrack()->envFrames(); + // if notes have zero length due to rounding set the length to a small value + tick_t noteLength = static_cast(qMax(1.0f, ceil(envFrames / Engine::framesPerTick()))); + cur_note.setLength(MidiTime(noteLength)); + } + // select it cur_note.setSelected( true ); diff --git a/src/tracks/Pattern.cpp b/src/tracks/Pattern.cpp index 125e84a1f57..59976f1364f 100644 --- a/src/tracks/Pattern.cpp +++ b/src/tracks/Pattern.cpp @@ -218,6 +218,7 @@ Note * Pattern::addNote( const Note & _new_note, const bool _quant_pos ) m_notes.insert(std::upper_bound(m_notes.begin(), m_notes.end(), new_note, Note::lessThan), new_note); instrumentTrack()->unlock(); + adjustSteps(); checkType(); updateLength(); @@ -244,7 +245,6 @@ void Pattern::removeNote( Note * _note_to_del ) ++it; } instrumentTrack()->unlock(); - checkType(); updateLength(); @@ -252,6 +252,12 @@ void Pattern::removeNote( Note * _note_to_del ) } +void Pattern::adjustSteps() +{ + m_steps = qMax(1, MidiTime(m_notes.last()->pos()).nextFullBar()) * MidiTime::stepsPerBar(); +} + + // returns a pointer to the note at specified step, or NULL if note doesn't exist Note * Pattern::noteAtStep( int _step )