dan@367
|
1 /*
|
dan@367
|
2 iTunes connection for
|
dan@367
|
3 Sonic Visualiser
|
dan@367
|
4 An audio file viewer and annotation editor.
|
dan@367
|
5 Centre for Digital Music, Queen Mary, University of London.
|
dan@367
|
6 This file copyright 2010 Dan Stowell and QMUL.
|
dan@367
|
7
|
dan@367
|
8 This program is free software; you can redistribute it and/or
|
dan@367
|
9 modify it under the terms of the GNU General Public License as
|
dan@367
|
10 published by the Free Software Foundation; either version 2 of the
|
dan@367
|
11 License, or (at your option) any later version. See the file
|
dan@367
|
12 COPYING included with this distribution for more information.
|
dan@367
|
13 */
|
dan@367
|
14
|
dan@380
|
15 #ifndef _SVITUNES_H_
|
dan@380
|
16 #define _SVITUNES_H_
|
dan@380
|
17
|
dan@367
|
18 #include <QString>
|
dan@367
|
19 #include <QStringList>
|
dan@367
|
20
|
dan@381
|
21 //#import <Foundation/Foundation.h>
|
dan@367
|
22
|
dan@381
|
23 /**
|
dan@381
|
24 * Class to handle communication with a running iTunes program on the system.
|
dan@381
|
25 * Only implemented for Mac at present, since using applescript communication.
|
dan@381
|
26 */
|
dan@381
|
27 class ITunesSVRemote : QObject
|
dan@381
|
28 {
|
dan@381
|
29 Q_OBJECT
|
dan@381
|
30
|
dan@381
|
31 public:
|
dan@381
|
32
|
dan@383
|
33 ITunesSVRemote() :
|
dan@383
|
34 m_playerState(STATE_UNKNOWN),
|
dan@383
|
35 m_playerPos(0)
|
dan@383
|
36 { }
|
dan@383
|
37 virtual ~ITunesSVRemote() { }
|
dan@381
|
38
|
dan@381
|
39 // Returns a list containing [posixpath, genre]
|
dan@381
|
40 QStringList getNowPlaying();
|
dan@383
|
41
|
dan@384
|
42 // When importing a fresh track we don't want the old cached playback position.
|
dan@384
|
43 // We can't simply update player position every time, since it only gets reported if playing.
|
dan@384
|
44 void resetPlayerState();
|
dan@384
|
45
|
dan@383
|
46 // Queries iTunes about player state and stores results locally
|
dan@383
|
47 void updatePlayerState();
|
dan@381
|
48
|
dan@383
|
49 // Whether the app is running. Only correct if updatePlayerState() recently invoked.
|
dan@383
|
50 bool isRunning();
|
dan@383
|
51
|
dan@383
|
52 // Whether the app is playing back. Only correct if updatePlayerState() recently invoked.
|
dan@383
|
53 bool isPlaying();
|
dan@383
|
54
|
dan@383
|
55 // Playback position in seconds. Only correct if updatePlayerState() recently invoked.
|
dan@383
|
56 unsigned int playerPos();
|
dan@381
|
57
|
dan@383
|
58 protected:
|
dan@383
|
59
|
dan@383
|
60 enum {
|
dan@383
|
61 STATE_UNKNOWN, // before ever querying
|
dan@383
|
62 STATE_CLOSED, // application not running
|
dan@383
|
63 // The rest correspond to states reported by iTunes itself:
|
dan@383
|
64 STATE_STOPPED,
|
dan@383
|
65 STATE_PLAYING,
|
dan@383
|
66 STATE_PAUSED,
|
dan@383
|
67 STATE_FASTFORWARDING,
|
dan@383
|
68 STATE_REWINDING
|
dan@383
|
69 };
|
dan@383
|
70
|
dan@383
|
71 // itunes has a set of states: {playing, stopped, ...}.
|
dan@383
|
72 // we also use "unknown" before checking,
|
dan@383
|
73 // and "closed" if iTunes isn't running.
|
dan@383
|
74 int m_playerState;
|
dan@383
|
75 unsigned int m_playerPos; // itunes only tells us seconds
|
dan@383
|
76
|
dan@381
|
77 };
|
dan@367
|
78
|
dan@380
|
79 #endif
|