File indexing completed on 2024-05-19 04:56:24

0001 /**
0002  * \file abstractfingerprintdecoder.h
0003  * Abstract base class for Chromaprint fingerprint decoder.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 15 Feb 2013
0008  *
0009  * Copyright (C) 2013-2024  Urs Fleisch
0010  *
0011  * This file is part of Kid3.
0012  *
0013  * Kid3 is free software; you can redistribute it and/or modify
0014  * it under the terms of the GNU General Public License as published by
0015  * the Free Software Foundation; either version 2 of the License, or
0016  * (at your option) any later version.
0017  *
0018  * Kid3 is distributed in the hope that it will be useful,
0019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0021  * GNU General Public License for more details.
0022  *
0023  * You should have received a copy of the GNU General Public License
0024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0025  */
0026 
0027 #pragma once
0028 
0029 #include <QObject>
0030 
0031 /**
0032  * Abstract base class for Chromaprint fingerprint decoder.
0033  */
0034 class AbstractFingerprintDecoder : public QObject {
0035   Q_OBJECT
0036 public:
0037   /**
0038    * Constructor.
0039    * @param parent parent object
0040    */
0041   explicit AbstractFingerprintDecoder(QObject* parent = nullptr);
0042 
0043   /**
0044    * Destructor.
0045    */
0046   ~AbstractFingerprintDecoder() override = 0;
0047 
0048   /**
0049    * Run decoder on audio file.
0050    * @param filePath path to audio file
0051    */
0052   virtual void start(const QString& filePath);
0053 
0054   /**
0055    * Stop decoder.
0056    * Can be used to stop the decoder when an error is found after
0057    * getting bufferReady() data.
0058    */
0059   virtual void stop();
0060 
0061   /**
0062    * Check if decoding has been stopped.
0063    * @return true if stopped.
0064    */
0065   virtual bool isStopped() const;
0066 
0067   /**
0068    * Create concrete fingerprint decoder.
0069    * @param parent parent object
0070    * @return fingerprint decoder instance.
0071    * @remarks This static method will be implemented by the concrete
0072    * fingerprint decoder which is used.
0073    */
0074   static AbstractFingerprintDecoder* createFingerprintDecoder(QObject* parent);
0075 
0076 signals:
0077   /**
0078    * Emitted when decoding starts.
0079    * @param sampleRate sample rate of the audio stream (in Hz)
0080    * @param channelCount numbers of channels in the audio stream (1 or 2)
0081    */
0082   void started(int sampleRate, int channelCount);
0083 
0084   /**
0085    * Emitted when decoded data is available.
0086    * @param data 16-bit signed integers in native byte-order
0087    */
0088   void bufferReady(QByteArray data);
0089 
0090   /**
0091    * Emitted when an error occurs.
0092    * @param code error code, enum FingerprintCalculator::Error
0093    */
0094   void error(int code);
0095 
0096   /**
0097    * Emitted when decoding finished successfully.
0098    * @param duration duration of stream in seconds
0099    */
0100   void finished(int duration);
0101 
0102 private:
0103   bool m_stopped;
0104 };