Skip to content

Commit

Permalink
Draw marker
Browse files Browse the repository at this point in the history
  • Loading branch information
Spekular authored and PhysSong committed Jul 27, 2019
1 parent c8c710b commit c14efd4
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 23 deletions.
11 changes: 11 additions & 0 deletions include/SampleTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ class SampleTCO : public TrackContentObject
bool isPlaying() const;
void setIsPlaying(bool isPlaying);

void inline setMarkerPos( int x )
{
m_markerPos = x;
}
void inline setMarkerEnabled( bool e )
{
m_marker = e;
}

public slots:
void setSampleBuffer( SampleBuffer* sb );
void setSampleFile( const QString & _sf );
Expand All @@ -87,6 +96,8 @@ public slots:
BoolModel m_recordModel;
bool m_isPlaying;

bool m_marker = false;
int m_markerPos = 0;

friend class SampleTCOView;

Expand Down
1 change: 1 addition & 0 deletions include/Track.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ protected slots:
MoveSelection,
Resize,
ResizeLeft,
Split,
CopySelection,
ToggleSelected
} ;
Expand Down
102 changes: 79 additions & 23 deletions src/core/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,31 +716,40 @@ void TrackContentObjectView::mousePressEvent( QMouseEvent * me )
{
setInitialPos( me->pos() );
setInitialOffsets();
if ( m_trackView->trackContainerView()->knifeMode()
&& me->button() == Qt::LeftButton )

if( !fixedTCOs() && me->button() == Qt::LeftButton )
{
SampleTCO * leftTCO = dynamic_cast<SampleTCO*>( m_tco );
if ( leftTCO )
if( m_trackView->trackContainerView()->knifeMode() )
{
const float ppt = m_trackView->trackContainerView()->pixelsPerTact();
const int x = mapToParent( me->pos() ).x();
MidiTime t = qMax<int>( 0, m_trackView->trackContainerView()->currentPosition() + x * MidiTime::ticksPerTact()/ppt);
if ( me->modifiers() & Qt::ControlModifier
|| me->modifiers() & Qt::AltModifier ) {}
else { t = t.quantize( gui->songEditor()->m_editor->getSnapSize() ); }
leftTCO->copy();
SampleTCO * rightTCO = new SampleTCO ( leftTCO->getTrack() );
rightTCO->paste();
m_action = Split;
SampleTCO * sTco = dynamic_cast<SampleTCO*>( m_tco );
if (sTco)
{
int markerPos = me->pos().x();

if ( me->modifiers() & Qt::ControlModifier
|| me->modifiers() & Qt::AltModifier )
{}
else {
const float ppt = m_trackView->trackContainerView()->pixelsPerTact();
MidiTime incs = MidiTime( MidiTime::ticksPerTact() * gui->songEditor()->m_editor->getSnapSize() );
MidiTime midiPos = markerPos * MidiTime::ticksPerTact() / ppt;
midiPos = midiPos.quantize(gui->songEditor()->m_editor->getSnapSize());
midiPos -= m_initialTCOPos % incs;
markerPos = midiPos * ppt / MidiTime::ticksPerTact();
}

leftTCO->changeLength( t - leftTCO->startPosition() );
rightTCO->movePosition(t);
rightTCO->changeLength( rightTCO->length() - leftTCO->length() );
rightTCO->setStartTimeOffset( leftTCO->startTimeOffset() - leftTCO->length() );
SampleTCO * sTco = dynamic_cast<SampleTCO*>( m_tco );
sTco->setMarkerPos( markerPos );
sTco->setMarkerEnabled( true );
update();
}
// We can't split anything except samples right now, so disable the
// action to avoid entering if statements we don't need to. This
// also saves us a few 'if(sTco)' checks
else { m_action = NoAction; }
}
}
else if( !fixedTCOs() && me->button() == Qt::LeftButton )
{
if( me->modifiers() & Qt::ControlModifier )
else if ( me->modifiers() & Qt::ControlModifier )
{
if( isSelected() )
{
Expand Down Expand Up @@ -1056,6 +1065,25 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me )
MidiTime::ticksPerTact() ) );
s_textFloat->moveGlobal( this, QPoint( width() + 2, height() + 2) );
}
else if( m_action == Split )
{
int markerPos = me->pos().x();

if ( me->modifiers() & Qt::ControlModifier
|| me->modifiers() & Qt::AltModifier )
{}
else {
MidiTime incs = MidiTime( MidiTime::ticksPerTact() * gui->songEditor()->m_editor->getSnapSize() );
MidiTime midiPos = markerPos * MidiTime::ticksPerTact() / ppt;
midiPos = midiPos.quantize(gui->songEditor()->m_editor->getSnapSize());
midiPos -= m_initialTCOPos % incs;
markerPos = midiPos * ppt / MidiTime::ticksPerTact();
}

SampleTCO * sTco = dynamic_cast<SampleTCO*>( m_tco );
sTco->setMarkerPos( markerPos );
update();
}
else
{
SampleTCO * sTco = dynamic_cast<SampleTCO*>( m_tco );
Expand Down Expand Up @@ -1092,12 +1120,40 @@ void TrackContentObjectView::mouseReleaseEvent( QMouseEvent * me )
{
setSelected( !isSelected() );
}

if( m_action == Move || m_action == Resize || m_action == ResizeLeft )
else if( m_action == Move || m_action == Resize || m_action == ResizeLeft )
{
// TODO: Fix m_tco->setJournalling() consistency
m_tco->setJournalling( true );
}
else if( m_action == Split )
{
SampleTCO * leftTCO = dynamic_cast<SampleTCO*>( m_tco );

leftTCO->setMarkerEnabled( false );

const float ppt = m_trackView->trackContainerView()->pixelsPerTact();
const int x = mapToParent( me->pos() ).x();
MidiTime t = qMax<int>( 0, m_trackView->trackContainerView()->currentPosition() + x * MidiTime::ticksPerTact()/ppt);

//Don't do anything if we slid off the TCO
if ( t <= m_initialTCOPos || t >= m_initialTCOEnd ){}
else {
if ( me->modifiers() & Qt::ControlModifier
|| me->modifiers() & Qt::AltModifier ) {}
else { t = t.quantize( gui->songEditor()->m_editor->getSnapSize() ); }

leftTCO->copy();
SampleTCO * rightTCO = new SampleTCO ( leftTCO->getTrack() );
rightTCO->paste();

leftTCO->changeLength( t - m_initialTCOPos );

rightTCO->movePosition(t);
rightTCO->changeLength( m_initialTCOEnd - t );
rightTCO->setStartTimeOffset( leftTCO->startTimeOffset() - leftTCO->length() );
}
}

m_action = NoAction;
delete m_hint;
m_hint = NULL;
Expand Down
4 changes: 4 additions & 0 deletions src/tracks/SampleTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,10 @@ void SampleTCOView::paintEvent( QPaintEvent * pe )
embed::getIconPixmap( "muted", size, size ) );
}

if ( m_tco->m_marker )
{
p.drawLine(m_tco->m_markerPos, rect().bottom(), m_tco->m_markerPos, rect().top());
}
// recording sample tracks is not possible at the moment

/* if( m_tco->isRecord() )
Expand Down

0 comments on commit c14efd4

Please sign in to comment.