Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/ClipView.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@


class QMenu;
class QMimeData;


namespace lmms
{
Expand Down Expand Up @@ -178,8 +180,9 @@ public slots:

float pixelsPerBar();


//! Turn a selection of clips into a DataFile used for drag-and-drop or copy
DataFile createClipDataFiles(const QVector<ClipView *> & clips) const;
virtual QMimeData* createClipboardData();

virtual void paintTextLabel(QString const & text, QPainter & painter);

Expand Down
55 changes: 50 additions & 5 deletions include/Clipboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
#define LMMS_CLIPBOARD_H

#include <QDomElement>
#include <QMap>
#include <QDropEvent>
#include <QPixmap>

#include "FileTypes.h"
#include "lmms_export.h"

class QMimeData;
Expand All @@ -38,10 +40,14 @@ namespace lmms::Clipboard
enum class MimeType
{
StringPair,
Default
// TODO rename Default to DataFile or something
// It is used as piano roll clipboard to hold DataFile XML
Default,
PlainText,
};

// Convenience Methods
void copyMimeData(QMimeData* m);
const QMimeData * getMimeData();
bool hasFormat( MimeType mT );

Expand All @@ -51,7 +57,10 @@ namespace lmms::Clipboard

// Helper methods for String Pair data
void copyStringPair( const QString & key, const QString & value );

//! deprecated - use MimeData::toStringPair instead
QString decodeKey( const QMimeData * mimeData );
//! deprecated - use MimeData::toStringPair instead
QString decodeValue( const QMimeData * mimeData );

inline const char * mimeType( MimeType type )
Expand All @@ -60,14 +69,50 @@ namespace lmms::Clipboard
{
case MimeType::StringPair:
return "application/x-lmms-stringpair";
break;
case MimeType::Default:
default:
return "application/x-lmms-clipboard";
break;
default:
return "text/plain";
}
}

} // namespace lmms::Clipboard




namespace lmms::MimeData
{
//! Create a new QMimeData from a string pair
LMMS_EXPORT QMimeData* fromStringPair(const QString& key, const QString& value);

//! Extract string pair from QMimeData
LMMS_EXPORT std::pair<QString, QString> toStringPair(const QMimeData* md);

} // namespace lmms::MimeData




namespace lmms::DragAndDrop
{
//! Start a QDrag from given widget, return mouse is released
LMMS_EXPORT void exec(QWidget* widget, QMimeData* md, const QPixmap& icon = {});

//! Start a QDrag containing a string pair
LMMS_EXPORT void execStringPairDrag(const QString& key, const QString& value, const QPixmap& icon, QWidget* widget);

//! Accept drag enter event if it contains a file of allowed type
LMMS_EXPORT bool acceptFile(QDragEnterEvent* dee, const std::initializer_list<FileType> allowedTypes);

//! Accept drag enter event if it contains a string pair of allowed type
LMMS_EXPORT bool acceptStringPair(QDragEnterEvent* dee, const std::initializer_list<QString> allowedKeys);

//! Get file path from drop event (empty if it doesn't match allowedType)
LMMS_EXPORT QString getFile(const QDropEvent* de, FileType allowedType);
LMMS_EXPORT std::pair<QString, FileType> getFileAndType(const QDropEvent* de);
LMMS_EXPORT std::pair<QString, QString> getFileAndExt(const QDropEvent* de);

} // namespace lmms::DragAndDrop

#endif // LMMS_CLIPBOARD_H
7 changes: 7 additions & 0 deletions include/DataFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QDomDocument>
#include <vector>

#include "FileTypes.h"
#include "lmms_export.h"

class QTextStream;
Expand Down Expand Up @@ -73,6 +74,12 @@ class LMMS_EXPORT DataFile : public QDomDocument

QString nameWithExtension( const QString& fn ) const;

//! Return preferred file extension for type
static QString extension(Type type);

//! List all DataFile file extensions (used to build FileTypes database)
static std::vector<std::pair<FileType, QString>> allSupportedFileTypes();

void write( QTextStream& strm );
bool writeFile(const QString& fn, bool withResources = false);
bool copyResources(const QString& resourcesDir); //!< Copies resources to the resourcesDir and changes the DataFile to use local paths to them
Expand Down
41 changes: 6 additions & 35 deletions include/FileBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include <QTreeWidget>

#include "FileTypes.h"
#include "SideBarWidget.h"
#include "lmmsconfig.h"

Expand Down Expand Up @@ -255,30 +256,6 @@ class Directory : public QTreeWidgetItem
class FileItem : public QTreeWidgetItem
{
public:
enum class FileType
{
Project,
Preset,
Sample,
SoundFont,
Patch,
Midi,
VstPlugin,
Unknown
} ;

enum class FileHandling
{
NotSupported,
LoadAsProject,
LoadAsPreset,
LoadByPlugin,
ImportAsProject
} ;


FileItem( QTreeWidget * parent, const QString & name,
const QString & path );
FileItem( const QString & name, const QString & path );

QString fullName() const
Expand All @@ -291,29 +268,23 @@ class FileItem : public QTreeWidgetItem
return( m_type );
}

inline FileHandling handling() const
{
return( m_handling );
}

//! True if the file can be used to create a new instrument track
inline bool isTrack() const
{
return m_handling == FileHandling::LoadAsPreset || m_handling == FileHandling::LoadByPlugin;
return m_type == FileType::InstrumentPreset
|| m_type == FileType::InstrumentAsset
|| m_type == FileType::Sample;
}

QString extension();
static QString extension( const QString & file );
static QString defaultFilters();

void startFileDrag(QWidget* dragSource);

private:
void initPixmaps();
void determineFileType();

QString m_path;
FileType m_type;
FileHandling m_handling;

} ;


Expand Down
64 changes: 64 additions & 0 deletions include/FileTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* FileTypes.h
*
* Copyright (c) 2025 allejok96 <gmail>
*
* 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_FILE_TYPES_H
#define LMMS_FILE_TYPES_H

#include <QString>

#include "lmms_export.h"

namespace lmms
{

class DataFile;

enum class FileType
{
Unknown,
ImportableProject, //!< any file that can be imported by some import filter
InstrumentAsset, //!< any file that can be loaded by some instrument plugin
InstrumentPreset, //!< DataFile of Instrument
MidiClipData, //!< DataFile of MidiClip
Project,
ProjectTemplate,
Sample, //! any audio file supported by SampleDecoder
};


namespace FileTypes
{
//! Create a filter string to be used in file dialogs
LMMS_EXPORT QString compileFilter(const std::initializer_list<FileType> fileTypes = {}, const QString& label = {});

//! Return a FileType for the given file extension
LMMS_EXPORT FileType find(const QString& ext);

//! Return an icon name for the given file extension
LMMS_EXPORT std::string iconName(const QString& ext);

} // namespace FileTypes

} // namespace lmms

#endif // LMMS_FILE_TYPES_H
18 changes: 15 additions & 3 deletions include/Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,23 @@ class LMMS_EXPORT Plugin : public Model, public JournallingObject
int version;
Type type;
const PixmapLoader * logo;
const char * supportedFileTypes; //!< csv list of extensions

struct FileTypeInfo
{
QString ext;
std::string iconName = {};
bool enablePreview = true;
};

const std::vector<FileTypeInfo> supportedFileTypes;

inline bool supportsFileType( const QString& extension ) const
{
return QString( supportedFileTypes ).split( QChar( ',' ) ).contains( extension );
for (const auto& fileTypeInfo : supportedFileTypes)
{
if (fileTypeInfo.ext == extension) { return true; }
}
return false;
}

/**
Expand All @@ -124,7 +136,7 @@ class LMMS_EXPORT Plugin : public Model, public JournallingObject
its sub plugin (using the attributes).
When keys are saved, those attributes are
written to XML in order to find the right sub
plugin when realoading.
plugin when reloading.

@note Any data that is not required to reference
the right Plugin or sub plugin should
Expand Down
2 changes: 2 additions & 0 deletions include/PluginFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class LMMS_EXPORT PluginFactory

/// Returns a list of all found plugins' PluginFactory::PluginInfo objects.
const PluginInfoList& pluginInfos() const;
/// Returns a list of all file extensions supported by any plugin
QStringList allSupportedExtensions();
/// Returns a plugin that support the given file extension
PluginInfoAndKey pluginSupportingExtension(const QString& ext);

Expand Down
25 changes: 25 additions & 0 deletions include/PluginView.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
#ifndef LMMS_GUI_PLUGIN_VIEW_H
#define LMMS_GUI_PLUGIN_VIEW_H

#include <QDragEnterEvent>
#include <QDropEvent>
#include <QWidget>

#include "Clipboard.h"
#include "ModelView.h"
#include "Plugin.h"

Expand All @@ -42,6 +45,28 @@ class LMMS_EXPORT PluginView : public QWidget, public ModelView
}

virtual bool isResizable() const { return false; }

protected:
void dragEnterEvent(QDragEnterEvent* dee) override
{
const auto [path, ext] = DragAndDrop::getFileAndExt(dee);

if (castModel<Plugin>()->descriptor()->supportsFileType(ext))
{
dee->acceptProposedAction();
}
}

void dropEvent(QDropEvent* de) override
{
const auto [path, ext] = DragAndDrop::getFileAndExt(de);

if (castModel<Plugin>()->descriptor()->supportsFileType(ext))
{
castModel<Plugin>()->loadFile(path);
de->accept();
}
}
};

} // namespace lmms::gui
Expand Down
1 change: 1 addition & 0 deletions include/SampleClipView.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public slots:
void mouseDoubleClickEvent( QMouseEvent * ) override;
void paintEvent( QPaintEvent * ) override;

QMimeData* createClipboardData() override;

private:
SampleClip * m_clip;
Expand Down
3 changes: 2 additions & 1 deletion include/SampleDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <string>
#include <vector>

#include "lmms_export.h"
#include "SampleFrame.h"

namespace lmms {
Expand All @@ -49,7 +50,7 @@ class SampleDecoder
};

static auto decode(const QString& audioFile) -> std::optional<Result>;
static auto supportedAudioTypes() -> const std::vector<AudioType>&;
LMMS_EXPORT static auto supportedAudioTypes() -> const std::vector<AudioType>&;
};
} // namespace lmms

Expand Down
Loading
Loading