-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding sample exporter #7627
Open
szeli1
wants to merge
33
commits into
LMMS:master
Choose a base branch
from
szeli1:sample_export
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
adding sample exporter #7627
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
1be7bb8
LmmsExporterSample_adding_class
szeli1 318d8b4
CMakeLists_adding_new_class_target
szeli1 a9248c4
LmmsExporterSample_fixing_printf
szeli1 50d20a7
SampleClip_implementing_static_exporter
szeli1 3d98c77
SampleClipView_implementing_exporting_context_menu_option
szeli1 0c630d0
LmmsExporterSample_fixing_typo
szeli1 baab754
SamleClipView_fixing_typo
szeli1 77cfaae
LmmsExporterSample_removing_blank_line
szeli1 58f4e15
LmmsExporterSample_removing_LMMS_EXPORT
szeli1 b25142f
LmmsExporterSample_removing_ifdef
szeli1 61e7ca9
LmmsExporterSample_removing_more_blank_lines
szeli1 2bc670d
LmmsMassExporter_renaming
szeli1 f87af45
LmmsMassExporter_moving_sndfile_code_to_new_class
szeli1 071a002
CMakeLists_updating_class_names
szeli1 0e34ec4
SampleClip_updating_class_names
szeli1 8bf5f0e
SampleClipView_updating_class_names
szeli1 98cd250
LmmsMassExporter_removing_include_QFile
szeli1 02025eb
LmmsMassExporter_implementing_callback
szeli1 adba327
SampleClip_implementing_sample_reloading
szeli1 5c30c30
SampleClipView_updating_names
szeli1 3566660
Use FileDialog::getSaveFileName
michaelgregorius 7c317b4
LmmsMassExporter_moving_flac_exporter
szeli1 e19bb60
FlacExporter_moving_to_new_file
szeli1 1ba312e
LmmsMassExporter_updating_description
szeli1 2021092
Merge remote-tracking branch 'origin/sample_export' into sample_export
szeli1 0452b7f
CMakeLists_adding_FlacExporter_cmake_target
szeli1 5228076
LmmsMassExporter_removing_blank_line
szeli1 5fa60b3
Save file with user selected name
michaelgregorius 5a0eeb7
LmmsMassExporter_renaming_to_ThreadedExportManager
szeli1 96f9888
CMakeLists_renaming_class
szeli1 65ec0af
SampleClipView_removing_LmmsMassExporter_include
szeli1 9fec78c
SampleClip_renaming_class
szeli1 bc59f5f
FlacExporter_adding_sync_function_before_destructing
szeli1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* FlacExporter.h - exports .flac files outside of AudioEngine | ||
* | ||
* Copyright (c) 2024 - 2025 szeli1 | ||
* | ||
* 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_FLAC_EXPORTER_H | ||
#define LMMS_FLAC_EXPORTER_H | ||
|
||
#include <sndfile.h> | ||
|
||
#include <QString> | ||
|
||
namespace lmms | ||
{ | ||
|
||
class SampleFrame; | ||
|
||
class FlacExporter | ||
{ | ||
public: | ||
FlacExporter(int sampleRate, int bitDepth, const QString& outputLocationAndName); | ||
~FlacExporter(); | ||
|
||
void writeThisBuffer(const SampleFrame* samples, size_t sampleCount); | ||
bool getIsSuccesful() const; | ||
|
||
private: | ||
bool m_isSuccesful; | ||
SNDFILE* m_fileDescriptor; | ||
}; | ||
|
||
} // namespace lmms | ||
|
||
#endif // LMMS_FLAC_EXPORTER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* ThreadedExportManager.h - exports files in .flac format on an other thread | ||
* | ||
* Copyright (c) 2024 - 2025 szeli1 | ||
* | ||
* 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_THREADED_EXPORT_MANAGER_H | ||
#define LMMS_THREADED_EXPORT_MANAGER_H | ||
|
||
#include <atomic> | ||
#include <memory> | ||
#include <thread> | ||
#include <tuple> | ||
#include <vector> | ||
#include <mutex> | ||
|
||
#include <sndfile.h> | ||
|
||
#include <QString> | ||
|
||
namespace lmms | ||
{ | ||
|
||
class SampleBuffer; | ||
|
||
typedef void (*callbackFn)(void*); | ||
|
||
class ThreadedExportManager | ||
{ | ||
public: | ||
ThreadedExportManager(); | ||
~ThreadedExportManager(); | ||
|
||
//! outputLocationAndName: should include path and name, could include ".flac" | ||
void startExporting(const QString& outputLocationAndName, std::shared_ptr<const SampleBuffer> buffer, callbackFn callbackFunction = nullptr, void* callbackObject = nullptr); | ||
void stopExporting(); | ||
|
||
//void writeBuffer(const SampleFrame* _ab, fpp_t const frames); | ||
|
||
private: | ||
static void threadedExportFunction(ThreadedExportManager* thisExporter, volatile std::atomic<bool>* abortExport); | ||
|
||
void stopThread(); | ||
bool openFile(const QString& outputLocationAndName, std::shared_ptr<const SampleBuffer> buffer); | ||
void exportBuffer(std::shared_ptr<const SampleBuffer> buffer); | ||
void closeFile(); | ||
|
||
std::vector<std::tuple<QString, std::shared_ptr<const SampleBuffer>, callbackFn, void*>> m_buffers; | ||
|
||
volatile std::atomic<bool> m_abortExport; | ||
bool m_isThreadRunning; | ||
std::mutex m_readMutex; | ||
std::thread* m_thread; | ||
}; | ||
|
||
} // namespace lmms | ||
|
||
#endif // LMMS_THREADED_EXPORT_MANAGER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* ThreadedExportManager.cpp - exports files in .flac format on an other thread | ||
* | ||
* Copyright (c) 2024 - 2025 szeli1 | ||
* | ||
* 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. | ||
* | ||
*/ | ||
|
||
#include "ThreadedExportManager.h" | ||
|
||
#include "FlacExporter.h" | ||
#include "SampleBuffer.h" | ||
|
||
namespace lmms | ||
{ | ||
|
||
ThreadedExportManager::ThreadedExportManager() : | ||
m_abortExport(false), | ||
m_isThreadRunning(false), | ||
m_readMutex(), | ||
m_thread(nullptr) | ||
{} | ||
|
||
ThreadedExportManager::~ThreadedExportManager() | ||
{ | ||
stopExporting(); | ||
} | ||
|
||
|
||
void ThreadedExportManager::startExporting(const QString& outputLocationAndName, std::shared_ptr<const SampleBuffer> buffer, callbackFn callbackFunction, void* callbackObject) | ||
{ | ||
m_readMutex.lock(); | ||
m_buffers.push_back(std::make_tuple(outputLocationAndName, buffer, callbackFunction, callbackObject)); | ||
m_readMutex.unlock(); | ||
|
||
if (m_isThreadRunning == false) | ||
{ | ||
stopExporting(); | ||
m_isThreadRunning = true; | ||
m_thread = new std::thread(&ThreadedExportManager::threadedExportFunction, this, &m_abortExport); | ||
} | ||
} | ||
|
||
void ThreadedExportManager::stopExporting() | ||
{ | ||
if (m_thread != nullptr) | ||
{ | ||
if (m_isThreadRunning == true) | ||
{ | ||
m_abortExport = true; | ||
} | ||
m_thread->join(); | ||
delete m_thread; | ||
m_thread = nullptr; | ||
m_isThreadRunning = false; | ||
m_abortExport = false; | ||
} | ||
} | ||
|
||
|
||
void ThreadedExportManager::threadedExportFunction(ThreadedExportManager* thisExporter, volatile std::atomic<bool>* abortExport) | ||
{ | ||
thisExporter->m_isThreadRunning = true; | ||
|
||
while (*abortExport == false) | ||
{ | ||
std::tuple<QString, std::shared_ptr<const SampleBuffer>, callbackFn, void*> curBuffer = std::make_tuple(QString(""), nullptr, nullptr, nullptr); | ||
thisExporter->m_readMutex.lock(); | ||
bool shouldExit = thisExporter->m_buffers.size() <= 0; | ||
if (shouldExit == false) | ||
{ | ||
curBuffer = thisExporter->m_buffers[thisExporter->m_buffers.size() - 1]; | ||
thisExporter->m_buffers.pop_back(); | ||
} | ||
thisExporter->m_readMutex.unlock(); | ||
if (shouldExit) { break; } | ||
|
||
// important new scope | ||
{ | ||
FlacExporter flacExporter(std::get<1>(curBuffer)->sampleRate(), 24, std::get<0>(curBuffer)); | ||
if (flacExporter.getIsSuccesful()) | ||
{ | ||
flacExporter.writeThisBuffer(std::get<1>(curBuffer)->data(), std::get<1>(curBuffer)->size()); | ||
} | ||
} | ||
|
||
if (std::get<2>(curBuffer)) | ||
{ | ||
// calling callback funcion | ||
std::get<2>(curBuffer)(std::get<3>(curBuffer)); | ||
} | ||
} | ||
|
||
thisExporter->m_isThreadRunning = false; | ||
} | ||
|
||
} // namespace lmms |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I have thought a bit more about it I do not think that replacing the sample with the one we have just exported is a good idea.
Let's say you have a project with all the samples contained in the project. You now want to export the sample to a different folder outside of the project just to save it. In this case the project file would now point to a file outside of the project folder which might not be the intended effect.
IMO the export feature should simply export the file to wherever the users want. If users want to replace the sample with the exported one it should either be an option in the export dialog (initially disabled) or they should explicitly replace the samples themselves after the export.
Doing it as it is currently done will likely lead to "chaos".