PageRenderTime 438ms CodeModel.GetById 111ms app.highlight 192ms RepoModel.GetById 123ms app.codeStats 1ms

/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
 21#ifndef AUDIOENGINE_H
 22#define AUDIOENGINE_H
 23
 24#include "../Typedefs.h"
 25
 26#include <QStringList>
 27#include <functional>
 28
 29#include "DllMacro.h"
 30
 31class NetworkReply;
 32class AudioEnginePrivate;
 33
 34class DLLEXPORT AudioEngine : public QObject
 35{
 36Q_OBJECT
 37
 38public:
 39    enum AudioErrorCode { StreamReadError, AudioDeviceError, DecodeError, UnknownError, NoError };
 40    enum AudioState { Stopped = 0, Playing = 1, Paused = 2, Error = 3, Loading = 4 };
 41    enum AudioChannel { LeftChannel, LeftSurroundChannel, RightChannel , RightSurroundChannel, CenterChannel , SubwooferChannel };
 42
 43    static AudioEngine* instance();
 44
 45    explicit AudioEngine();
 46    ~AudioEngine();
 47
 48    /**
 49     * List the MIME types we can play.
 50     *
 51     * This list might not include all possible MIME types that can be played.
 52     * If you know that a certain service always returns a specific MIME type
 53     * not reported here, we still might be able to play this media. Please
 54     * check the individual backends why they do not report it and if every
 55     * (recent) version supports this type.
 56     *
 57     * @return A list of playable MIME types.
 58     */
 59    QStringList supportedMimeTypes() const;
 60
 61    /**
 62     * Reports the current set volume in percent (0-100).
 63     *
 64     * @return Current volume in percent.
 65     */
 66    unsigned int volume() const;
 67
 68    AudioState state() const;
 69    bool isPlaying() const;
 70    bool isPaused() const;
 71    bool isStopped() const;
 72    bool isMuted() const;
 73
 74    /**
 75     * Returns the PlaylistInterface of the currently playing track.
 76     *
 77     * Note: This might be different to the current playlist!
 78     */
 79    Tomahawk::playlistinterface_ptr currentTrackPlaylist() const;
 80
 81    /**
 82     * Returns the PlaylistInterface of the current playlist.
 83     *
 84     * Note: The currently playing track might still be from a different
 85     * playlist!
 86     */
 87    Tomahawk::playlistinterface_ptr playlist() const;
 88
 89    Tomahawk::result_ptr currentTrack() const;
 90    Tomahawk::query_ptr stopAfterTrack() const;
 91
 92    /**
 93     * Get the current position in the media.
 94     *
 95     * As the user might seek forwards and backwards this only returns the
 96     * location in the media, not the actual time that the media was already
 97     * playing.
 98     * @return The current time in milliseconds.
 99     */
100    qint64 currentTime() const;
101
102    /**
103     * Returns the total duration of the currently playing track.
104     *
105     * For some media this time might only be an estimate as metadate might
106     * not have reported a duration and thus the duration is estimated. During
107     * playback we might get a better estimate so that the return value may
108     * differ between multiple calls.
109     *
110     * @return The total duration in milliseconds.
111     */
112    qint64 currentTrackTotalTime() const;
113
114    void setDspCallback( std::function< void( int state, int frameNumber, float* samples, int nb_channels, int nb_samples ) > cb );
115
116public slots:
117    void playPause();
118    void play();
119    void pause();
120    void stop( AudioErrorCode errorCode = NoError );
121
122    void previous();
123    void next();
124
125    bool canGoPrevious();
126    bool canGoNext();
127    bool canSeek();
128
129    void seek( qint64 ms );
130    void seek( int ms ); // for compatibility with seekbar in audiocontrols
131    void setVolume( int percentage );
132    void lowerVolume();
133    void raiseVolume();
134    void mute();
135    void toggleMute();
136
137    void play( const QUrl& url );
138    void playItem( Tomahawk::playlistinterface_ptr playlist, const Tomahawk::result_ptr& result, const Tomahawk::query_ptr& fromQuery = Tomahawk::query_ptr() );
139    void playItem( Tomahawk::playlistinterface_ptr playlist, const Tomahawk::query_ptr& query );
140    void playItem( const Tomahawk::artist_ptr& artist );
141    void playItem( const Tomahawk::album_ptr& album );
142    void playPlaylistInterface( const Tomahawk::playlistinterface_ptr& playlist );
143    void setPlaylist( Tomahawk::playlistinterface_ptr playlist );
144    void setQueue( const Tomahawk::playlistinterface_ptr& queue );
145
146    void setStopAfterTrack( const Tomahawk::query_ptr& query );
147
148    void setRepeatMode( Tomahawk::PlaylistModes::RepeatMode mode );
149    void setShuffled( bool enabled );
150
151signals:
152    void initialized();
153
154    void loading( const Tomahawk::result_ptr track );
155    void started( const Tomahawk::result_ptr track );
156    void finished( const Tomahawk::result_ptr track );
157    void stopped();
158    void paused();
159    void resumed();
160
161//    void audioDataReady( QMap< AudioEngine::AudioChannel, QVector<qint16> > data );
162
163    void stopAfterTrackChanged();
164
165    void seeked( qint64 ms );
166
167    void shuffleModeChanged( bool enabled );
168    void repeatModeChanged( Tomahawk::PlaylistModes::RepeatMode mode );
169    void controlStateChanged();
170    void stateChanged( AudioState newState, AudioState oldState );
171    void volumeChanged( int volume /* in percent */ );
172    void mutedChanged( bool muted );
173
174    void timerMilliSeconds( qint64 msElapsed );
175    void timerSeconds( unsigned int secondsElapsed );
176    void timerPercentage( unsigned int percentage );
177    void trackPosition( float position );
178
179    void playlistChanged( Tomahawk::playlistinterface_ptr playlist );
180    void currentTrackPlaylistChanged( Tomahawk::playlistinterface_ptr playlist );
181
182    void error( AudioEngine::AudioErrorCode errorCode );
183
184private slots:
185    void loadTrack( const Tomahawk::result_ptr& result ); //async!
186    void gotStreamUrl( const QVariantMap& data );
187    void gotRedirectedStreamUrl( const Tomahawk::result_ptr& result, NetworkReply* reply );
188
189
190    void performLoadIODevice( const Tomahawk::result_ptr& result, const QString& url ); //only call from loadTrack kthxbi
191    void performLoadTrack( const Tomahawk::result_ptr result, const QString& url, QSharedPointer< QIODevice > io ); //only call from loadTrack or performLoadIODevice kthxbi
192    void loadPreviousTrack();
193    void loadNextTrack();
194
195    void onVolumeChanged( qreal volume );
196    void timerTriggered( qint64 time );
197    void onPositionChanged( float new_position );
198
199    void setCurrentTrack( const Tomahawk::result_ptr& result );
200    void onNowPlayingInfoReady( const Tomahawk::InfoSystem::InfoType type );
201    void onPlaylistNextTrackAvailable();
202
203    void sendNowPlayingNotification( const Tomahawk::InfoSystem::InfoType type );
204    void sendWaitingNotification() const;
205
206private:
207    void setState( AudioState state );
208    void setCurrentTrackPlaylist( const Tomahawk::playlistinterface_ptr& playlist );
209
210//    void audioDataArrived( QMap< AudioEngine::AudioChannel, QVector< qint16 > >& data );
211
212
213    Q_DECLARE_PRIVATE( AudioEngine )
214    AudioEnginePrivate* d_ptr;
215};
216
217#endif // AUDIOENGINE_H