Files
lmms/include/AutomationTrack.h
IanCaio e2bb606341 Fixes createTCO method on some classes (#5699)
* Fixes createTCO method on some classes

	Classes that inherit from "Track", also inherit the createTCO method. That method takes a MidiTime position as an argument, but except on the class SampleTrack that argument was ignored. That lead to unnecessary calls to TCO->movePosition after creating a TCO in many parts of the codebase (making the argument completely redundant) and even to a bug on the BBEditor, caused by a call to createTCO that expected the position to be set on the constructor (see issue #5673).

	That PR adds code to move the TCO to the appropriate position inside the constructor of the classes that didn't have it, fixes the code style on the SampleTrack createTCO method and removes the now unneeded calls to movePosition from source files on src/ and plugins/. On Track::loadSettings there was a call to saveJournallingState(false) followed immediately by restoreJournallingState() which was deleted because it's redundant (probably a left over from copying the code from pasteSelection?).

* Fix code style issues

	Fixes code style issues on some files (except for ones where the current statements already had a different code style. In those the used code style was kept for consistency).

* Fixes more code style issues

* Fixes code style issues on the parameter name

	Fixes code style issue on the parameter name of createTCO, where _pos was supposed to be just pos. The existing code had the old style and I ended up replicating it on the other methods.

* Code style fixes

	Fixes code style in the changed lines.

* Fixes bug with dragging to negative positions

	There was a bug (already present before this PR) where dragging
a selection before MidiTime 0 would result in some TCOs being placed on
negative positions. This PR fixes this bug by applying the following
changes:

	1) TrackContentObject::movePosition now moves the TCO to
positions equal or above 0 only.
	2) Because of the previous change, I removed the line that
calculated the max value between 0 and the new position on
TrackContentObjectView::mouseMoveEvent when dragging a single TCO (and
added a line updating the value to the real new position of the TCO so
the label displays the position correctly).
	3) Unrelated to this bug, but removed an unnecessary call to
TrackContentWidget::changePosition on the left resize of sample TCOs
because it will already be called when movePosition triggers the
positionChanged signal.
	4) Added some logic to the TrackContentWidget::pasteSelection
method to find the left most TCO being pasted and make sure that the
offset is corrected so it doesn't end up on a negative position (similar
to the logic for the MoveSelection action).
	5) Removed another line that calculated the max between 0 and
the new position on Track::removeBar since it's now safe to call
movePosition with negative values.

* Uses std::max instead of a conditional statement

	As suggested by Spekular, we use std::max instead of a
conditional statement to correct the value of offset if it positions a
TCO on a negative position.
2020-11-07 13:54:04 +01:00

75 lines
2.1 KiB
C++

/*
* AutomationTrack.h - declaration of class AutomationTrack, which handles
* automation of objects without a track
*
* Copyright (c) 2008-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2006-2008 Javier Serrano Polo <jasp00/at/users.sourceforge.net>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#ifndef AUTOMATION_TRACK_H
#define AUTOMATION_TRACK_H
#include "Track.h"
class AutomationTrack : public Track
{
Q_OBJECT
public:
AutomationTrack( TrackContainer* tc, bool _hidden = false );
virtual ~AutomationTrack() = default;
virtual bool play( const MidiTime & _start, const fpp_t _frames,
const f_cnt_t _frame_base, int _tco_num = -1 ) override;
QString nodeName() const override
{
return "automationtrack";
}
TrackView * createView( TrackContainerView* ) override;
TrackContentObject* createTCO(const MidiTime & pos) override;
virtual void saveTrackSpecificSettings( QDomDocument & _doc,
QDomElement & _parent ) override;
void loadTrackSpecificSettings( const QDomElement & _this ) override;
private:
friend class AutomationTrackView;
} ;
class AutomationTrackView : public TrackView
{
public:
AutomationTrackView( AutomationTrack* at, TrackContainerView* tcv );
virtual ~AutomationTrackView() = default;
void dragEnterEvent( QDragEnterEvent * _dee ) override;
void dropEvent( QDropEvent * _de ) override;
} ;
#endif