mirror of
https://github.com/LMMS/lmms.git
synced 2025-12-31 10:38:05 -05:00
Check if a non-empty buffer was loaded and only set the sample clip if that's the case. ## Other changes Move setting the song to modified towards the core in the context of `SampleClip`. Previously the `SampleClipView` did this but it's none of it's business. Introduce `SampleClip::changeLengthToSampleLength` which changes the length of the clip to the length of the sample. This was also previously done by the view which is again the wrong place to do the necessary calculations. An unnecessary `static_cast` was removed while carrying over the code. Add the method `SampleClip::hasSampleFileLoaded` which checks if the loaded sample corresponds to a given file name. Fix code formatting.
109 lines
2.5 KiB
C++
109 lines
2.5 KiB
C++
/*
|
|
* SampleClip.h
|
|
*
|
|
* Copyright (c) 2005-2014 Tobias Doerffel <tobydox/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 LMMS_SAMPLE_CLIP_H
|
|
#define LMMS_SAMPLE_CLIP_H
|
|
|
|
#include <memory>
|
|
#include "Clip.h"
|
|
#include "Sample.h"
|
|
|
|
namespace lmms
|
|
{
|
|
|
|
class SampleBuffer;
|
|
|
|
namespace gui
|
|
{
|
|
|
|
class SampleClipView;
|
|
|
|
} // namespace gui
|
|
|
|
|
|
class SampleClip : public Clip
|
|
{
|
|
Q_OBJECT
|
|
mapPropertyFromModel(bool,isRecord,setRecord,m_recordModel);
|
|
public:
|
|
SampleClip(Track* track, Sample sample, bool isPlaying);
|
|
SampleClip(Track* track);
|
|
SampleClip( const SampleClip& orig );
|
|
~SampleClip() override;
|
|
|
|
SampleClip& operator=( const SampleClip& that ) = delete;
|
|
|
|
void changeLength( const TimePos & _length ) override;
|
|
void changeLengthToSampleLength();
|
|
const QString& sampleFile() const;
|
|
bool hasSampleFileLoaded(const QString & filename) const;
|
|
|
|
void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
|
|
void loadSettings( const QDomElement & _this ) override;
|
|
inline QString nodeName() const override
|
|
{
|
|
return "sampleclip";
|
|
}
|
|
|
|
Sample& sample()
|
|
{
|
|
return m_sample;
|
|
}
|
|
|
|
TimePos sampleLength() const;
|
|
void setSampleStartFrame( f_cnt_t startFrame );
|
|
void setSamplePlayLength( f_cnt_t length );
|
|
gui::ClipView * createView( gui::TrackView * _tv ) override;
|
|
|
|
|
|
bool isPlaying() const;
|
|
void setIsPlaying(bool isPlaying);
|
|
void setSampleBuffer(std::shared_ptr<const SampleBuffer> sb);
|
|
|
|
public slots:
|
|
void setSampleFile(const QString& sf);
|
|
void updateLength();
|
|
void toggleRecord();
|
|
void playbackPositionChanged();
|
|
void updateTrackClips();
|
|
|
|
|
|
private:
|
|
Sample m_sample;
|
|
BoolModel m_recordModel;
|
|
bool m_isPlaying;
|
|
|
|
friend class gui::SampleClipView;
|
|
|
|
|
|
signals:
|
|
void sampleChanged();
|
|
void wasReversed();
|
|
} ;
|
|
|
|
|
|
} // namespace lmms
|
|
|
|
#endif // LMMS_SAMPLE_CLIP_H
|