Skip to content

Commit

Permalink
Drop sample on sampletracks (LMMS#5043)
Browse files Browse the repository at this point in the history
* implements drag and drop samples to sampletracks

* clean up / take care of timeLineWidget heigth in songeditor

* unused memeber removed

* clean up

* Update include/TrackContainerView.h

Co-Authored-By: Spekular <Spekular@users.noreply.github.com>

* Update src/gui/TrackContainerView.cpp

Co-Authored-By: Spekular <Spekular@users.noreply.github.com>

* Update src/gui/TrackContainerView.cpp

Co-Authored-By: Spekular <Spekular@users.noreply.github.com>

* Update src/gui/editors/SongEditor.cpp

Co-Authored-By: Spekular <Spekular@users.noreply.github.com>

* load AFP if we don't drop on a sample track

* take care of timeLineWidget size changes

* clean up

* consolidate some code

* requested changes by code review

* move logic to SampleTrackView

* clean up

* clean up

* clean up
  • Loading branch information
BaraMGB committed Jun 28, 2019
1 parent 62dd0c8 commit ed75496
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
4 changes: 3 additions & 1 deletion include/SampleTrack.h
Expand Up @@ -139,7 +139,7 @@ class SampleTrack : public Track
virtual bool play( const MidiTime & _start, const fpp_t _frames,
const f_cnt_t _frame_base, int _tco_num = -1 );
virtual TrackView * createView( TrackContainerView* tcv );
virtual TrackContentObject * createTCO( const MidiTime & _pos );
virtual TrackContentObject * createTCO(const MidiTime & pos);


virtual void saveTrackSpecificSettings( QDomDocument & _doc,
Expand Down Expand Up @@ -218,6 +218,8 @@ public slots:
return "SampleTrackView";
}

void dragEnterEvent(QDragEnterEvent *dee);
void dropEvent(QDropEvent *de);

private slots:
void assignFxLine( int channelIndex );
Expand Down
45 changes: 43 additions & 2 deletions src/tracks/SampleTrack.cpp
Expand Up @@ -710,9 +710,11 @@ TrackView * SampleTrack::createView( TrackContainerView* tcv )



TrackContentObject * SampleTrack::createTCO( const MidiTime & )
TrackContentObject * SampleTrack::createTCO(const MidiTime & pos)
{
return new SampleTCO( this );
SampleTCO * sTco = new SampleTCO(this);
sTco->movePosition(pos);
return sTco;
}


Expand Down Expand Up @@ -901,6 +903,45 @@ void SampleTrackView::modelChanged()




void SampleTrackView::dragEnterEvent(QDragEnterEvent *dee)
{
StringPairDrag::processDragEnterEvent(dee, QString("samplefile"));
}




void SampleTrackView::dropEvent(QDropEvent *de)
{
QString type = StringPairDrag::decodeKey(de);
QString value = StringPairDrag::decodeValue(de);

if (type == "samplefile")
{
int trackHeadWidth = ConfigManager::inst()->value("ui", "compacttrackbuttons").toInt()==1
? DEFAULT_SETTINGS_WIDGET_WIDTH_COMPACT + TRACK_OP_WIDTH_COMPACT
: DEFAULT_SETTINGS_WIDGET_WIDTH + TRACK_OP_WIDTH;

int xPos = de->pos().x() < trackHeadWidth
? trackHeadWidth
: de->pos().x();

MidiTime tcoPos = trackContainerView()->fixedTCOs()
? MidiTime(0)
: MidiTime(((xPos - trackHeadWidth) / trackContainerView()->pixelsPerTact()
* MidiTime::ticksPerTact()) + trackContainerView()->currentPosition()
).toNearestTact();

SampleTCO * sTco = static_cast<SampleTCO*>(getTrack()->createTCO(tcoPos));
if (sTco) { sTco->setSampleFile(value); }
}

}




SampleTrackWindow::SampleTrackWindow(SampleTrackView * tv) :
QWidget(),
ModelView(NULL, this),
Expand Down

0 comments on commit ed75496

Please sign in to comment.