File: K3BExportPlugin.h

package info (click to toggle)
kwave 25.04.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,272 kB
  • sloc: cpp: 56,173; xml: 817; perl: 688; sh: 57; makefile: 11
file content (176 lines) | stat: -rw-r--r-- 6,401 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// SPDX-FileCopyrightText: 2017 Thomas Eschenbacher <Thomas.Eschenbacher@gmx.de>
// SPDX-License-Identifier: GPL-2.0-or-later
/*************************************************************************
 *      K3BExportPlugin.h  -  export of K3b project files
 *                             -------------------
 *    begin                : Thu Apr 13 2017
 *    copyright            : (C) 2017 by Thomas Eschenbacher
 *    email                : Thomas.Eschenbacher@gmx.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef K3B_EXPORT_PLUGIN_H
#define K3B_EXPORT_PLUGIN_H

#include "config.h"

#include <QObject>
#include <QStringList>
#include <QUrl>
#include <QVariantList>
#include <QVector>

#include "libkwave/Plugin.h"

class QDomElement;

namespace Kwave
{

    class K3BExportPlugin: public Kwave::Plugin
    {
        Q_OBJECT
    public:

        typedef enum {
            OVERWRITE_EXISTING_FILES = 0,
            USE_NEW_FILE_NAMES       = 1
        } overwrite_policy_t;

        /**
         * Constructor
         * @param parent reference to our plugin manager
         * @param args argument list [unused]
         */
        K3BExportPlugin(QObject *parent, const QVariantList &args);

        /** Destructor */
        ~K3BExportPlugin() override;

        /** @see Kwave::Plugin::load() */
        void load(QStringList &params) override;

        /**
         * Normally this method is used to set up all necessary parameters
         * for executing the plugin. This plugin uses it for performing
         * actions in the context of the GUI thread.
         *
         * @param params some parameters
         * @return string list with parameters or null pointer
         */
        QStringList *setup(QStringList &params) override;

        /**
         * Saves the K3b project file, using the settings made in "setup()"
         * @see Kwave::Plugin::start()
         */
        int start(QStringList &params) override;

        /** returns a list of all known detection patterns */
        static QStringList knownPatterns();

    protected:

        typedef struct {
            unsigned int   m_index;    /**< track index [1...N]           */
            QString        m_filename; /**< file name for saving          */
            sample_index_t m_start;    /**< start of the block [samples]  */
            sample_index_t m_length;   /**< length of the block [samples] */
            QString        m_title;    /**< title of the block            */
            QString        m_artist;   /**< artist of the song            */
        } BlockInfo;

        /** reads values from the parameter list */
        int interpreteParameters(QStringList &params);

        /**
         * determines the blocks which should be saved, including
         * start position, length and title.
         * @param base the base name, without indices, extension etc...
         * @param selection_left index of the first sample
         * @param selection_right index of the last sample
         */
        void scanBlocksToSave(const QString &base,
                              sample_index_t selection_left,
                              sample_index_t selection_right);

        /**
         * create a filename (with extension) out of a given name pattern
         * and index
         * @param pattern the pattern for creating the filename
         * @param index the index of the current file
         * @return the name of the file
         */
        QString createFileName(const QString &pattern, unsigned int index);

        /**
         * detects the meta data of a block from splitting the description
         * text of a label
         * @param text the description of a label
         * @param pattern a pattern describing the format of the text
         * @param block a BlockInfo structure that receives artist and title
         * @return true if the pattern did match, false otherwise
         */
        bool detectBlockMetaData(const QString &text,
                                 const QString &pattern,
                                 BlockInfo &block);

        /** save the "general" section */
        void saveGeneralDocumentData(QDomElement *part);

        /** save the K3b project document data */
        void saveDocumentData(QDomElement *docElem);

        /**
         * save the blocks through the saveblocks plugin
         * @param selection_only if true, save only the selection
         * @param out_dir output directory for saving the blocks
         * @param out_pattern the pattern for creating the block filenames
         * @return zero if succeeded, or error code if failed
         */
        int saveBlocks(bool selection_only,
                       const QString &out_dir,
                       const QString &out_pattern);

        /**
         * save the *.k3b file
         * @param k3b_filename path to the *.k3b file
         * @return zero if succeeded, or error code if failed
         */
        int saveK3BFile(const QString &k3b_filename);

    private:

        /** the URL of the project file */
        QUrl m_url;

        /** pattern for detecting title and artist */
        QString m_pattern;

        /** if true, export only the selected range */
        bool m_selection_only;

        /** directory to export the tracks into */
        QUrl m_export_location;

        /** overwrite existing files or create a new file name */
        overwrite_policy_t m_overwrite_policy;

        /** list of all blocks to save */
        QVector<BlockInfo> m_block_info;
    };
}

#endif /* K3B_EXPORT_PLUGIN_H */

//***************************************************************************
//***************************************************************************