/src/libtomahawk/audio/AudioEngine.h

http://github.com/tomahawk-player/tomahawk · C Header · 217 lines · 106 code · 45 blank · 66 comment · 0 complexity · e56ee3eb0d75ddf0d0e788ed0e83be85 MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2014, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4. * Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
  5. * Copyright 2013, Teo Mrnjavac <teo@kde.org>
  6. *
  7. * Tomahawk is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Tomahawk is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef AUDIOENGINE_H
  21. #define AUDIOENGINE_H
  22. #include "../Typedefs.h"
  23. #include <QStringList>
  24. #include <functional>
  25. #include "DllMacro.h"
  26. class NetworkReply;
  27. class AudioEnginePrivate;
  28. class DLLEXPORT AudioEngine : public QObject
  29. {
  30. Q_OBJECT
  31. public:
  32. enum AudioErrorCode { StreamReadError, AudioDeviceError, DecodeError, UnknownError, NoError };
  33. enum AudioState { Stopped = 0, Playing = 1, Paused = 2, Error = 3, Loading = 4 };
  34. enum AudioChannel { LeftChannel, LeftSurroundChannel, RightChannel , RightSurroundChannel, CenterChannel , SubwooferChannel };
  35. static AudioEngine* instance();
  36. explicit AudioEngine();
  37. ~AudioEngine();
  38. /**
  39. * List the MIME types we can play.
  40. *
  41. * This list might not include all possible MIME types that can be played.
  42. * If you know that a certain service always returns a specific MIME type
  43. * not reported here, we still might be able to play this media. Please
  44. * check the individual backends why they do not report it and if every
  45. * (recent) version supports this type.
  46. *
  47. * @return A list of playable MIME types.
  48. */
  49. QStringList supportedMimeTypes() const;
  50. /**
  51. * Reports the current set volume in percent (0-100).
  52. *
  53. * @return Current volume in percent.
  54. */
  55. unsigned int volume() const;
  56. AudioState state() const;
  57. bool isPlaying() const;
  58. bool isPaused() const;
  59. bool isStopped() const;
  60. bool isMuted() const;
  61. /**
  62. * Returns the PlaylistInterface of the currently playing track.
  63. *
  64. * Note: This might be different to the current playlist!
  65. */
  66. Tomahawk::playlistinterface_ptr currentTrackPlaylist() const;
  67. /**
  68. * Returns the PlaylistInterface of the current playlist.
  69. *
  70. * Note: The currently playing track might still be from a different
  71. * playlist!
  72. */
  73. Tomahawk::playlistinterface_ptr playlist() const;
  74. Tomahawk::result_ptr currentTrack() const;
  75. Tomahawk::query_ptr stopAfterTrack() const;
  76. /**
  77. * Get the current position in the media.
  78. *
  79. * As the user might seek forwards and backwards this only returns the
  80. * location in the media, not the actual time that the media was already
  81. * playing.
  82. * @return The current time in milliseconds.
  83. */
  84. qint64 currentTime() const;
  85. /**
  86. * Returns the total duration of the currently playing track.
  87. *
  88. * For some media this time might only be an estimate as metadate might
  89. * not have reported a duration and thus the duration is estimated. During
  90. * playback we might get a better estimate so that the return value may
  91. * differ between multiple calls.
  92. *
  93. * @return The total duration in milliseconds.
  94. */
  95. qint64 currentTrackTotalTime() const;
  96. void setDspCallback( std::function< void( int state, int frameNumber, float* samples, int nb_channels, int nb_samples ) > cb );
  97. public slots:
  98. void playPause();
  99. void play();
  100. void pause();
  101. void stop( AudioErrorCode errorCode = NoError );
  102. void previous();
  103. void next();
  104. bool canGoPrevious();
  105. bool canGoNext();
  106. bool canSeek();
  107. void seek( qint64 ms );
  108. void seek( int ms ); // for compatibility with seekbar in audiocontrols
  109. void setVolume( int percentage );
  110. void lowerVolume();
  111. void raiseVolume();
  112. void mute();
  113. void toggleMute();
  114. void play( const QUrl& url );
  115. void playItem( Tomahawk::playlistinterface_ptr playlist, const Tomahawk::result_ptr& result, const Tomahawk::query_ptr& fromQuery = Tomahawk::query_ptr() );
  116. void playItem( Tomahawk::playlistinterface_ptr playlist, const Tomahawk::query_ptr& query );
  117. void playItem( const Tomahawk::artist_ptr& artist );
  118. void playItem( const Tomahawk::album_ptr& album );
  119. void playPlaylistInterface( const Tomahawk::playlistinterface_ptr& playlist );
  120. void setPlaylist( Tomahawk::playlistinterface_ptr playlist );
  121. void setQueue( const Tomahawk::playlistinterface_ptr& queue );
  122. void setStopAfterTrack( const Tomahawk::query_ptr& query );
  123. void setRepeatMode( Tomahawk::PlaylistModes::RepeatMode mode );
  124. void setShuffled( bool enabled );
  125. signals:
  126. void initialized();
  127. void loading( const Tomahawk::result_ptr track );
  128. void started( const Tomahawk::result_ptr track );
  129. void finished( const Tomahawk::result_ptr track );
  130. void stopped();
  131. void paused();
  132. void resumed();
  133. // void audioDataReady( QMap< AudioEngine::AudioChannel, QVector<qint16> > data );
  134. void stopAfterTrackChanged();
  135. void seeked( qint64 ms );
  136. void shuffleModeChanged( bool enabled );
  137. void repeatModeChanged( Tomahawk::PlaylistModes::RepeatMode mode );
  138. void controlStateChanged();
  139. void stateChanged( AudioState newState, AudioState oldState );
  140. void volumeChanged( int volume /* in percent */ );
  141. void mutedChanged( bool muted );
  142. void timerMilliSeconds( qint64 msElapsed );
  143. void timerSeconds( unsigned int secondsElapsed );
  144. void timerPercentage( unsigned int percentage );
  145. void trackPosition( float position );
  146. void playlistChanged( Tomahawk::playlistinterface_ptr playlist );
  147. void currentTrackPlaylistChanged( Tomahawk::playlistinterface_ptr playlist );
  148. void error( AudioEngine::AudioErrorCode errorCode );
  149. private slots:
  150. void loadTrack( const Tomahawk::result_ptr& result ); //async!
  151. void gotStreamUrl( const QVariantMap& data );
  152. void gotRedirectedStreamUrl( const Tomahawk::result_ptr& result, NetworkReply* reply );
  153. void performLoadIODevice( const Tomahawk::result_ptr& result, const QString& url ); //only call from loadTrack kthxbi
  154. void performLoadTrack( const Tomahawk::result_ptr result, const QString& url, QSharedPointer< QIODevice > io ); //only call from loadTrack or performLoadIODevice kthxbi
  155. void loadPreviousTrack();
  156. void loadNextTrack();
  157. void onVolumeChanged( qreal volume );
  158. void timerTriggered( qint64 time );
  159. void onPositionChanged( float new_position );
  160. void setCurrentTrack( const Tomahawk::result_ptr& result );
  161. void onNowPlayingInfoReady( const Tomahawk::InfoSystem::InfoType type );
  162. void onPlaylistNextTrackAvailable();
  163. void sendNowPlayingNotification( const Tomahawk::InfoSystem::InfoType type );
  164. void sendWaitingNotification() const;
  165. private:
  166. void setState( AudioState state );
  167. void setCurrentTrackPlaylist( const Tomahawk::playlistinterface_ptr& playlist );
  168. // void audioDataArrived( QMap< AudioEngine::AudioChannel, QVector< qint16 > >& data );
  169. Q_DECLARE_PRIVATE( AudioEngine )
  170. AudioEnginePrivate* d_ptr;
  171. };
  172. #endif // AUDIOENGINE_H