xref: /haiku/src/apps/mediaplayer/ControllerObserver.cpp (revision 922e7ba1f3228e6f28db69b0ded8f86eb32dea17)
1 /*
2  * Copyright 2007-2009, Haiku. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus <superstippi@gmx.de>
7  */
8 
9 
10 #include "ControllerObserver.h"
11 
12 #include <Message.h>
13 
14 #include "PlaylistItem.h"
15 
16 
17 ControllerObserver::ControllerObserver(BHandler* target, uint32 observeFlags)
18 	:
19 	AbstractLOAdapter(target),
20 	fObserveFlags(observeFlags)
21 {
22 }
23 
24 
25 ControllerObserver::~ControllerObserver()
26 {
27 }
28 
29 
30 void
31 ControllerObserver::FileFinished()
32 {
33 	if (!(fObserveFlags & OBSERVE_FILE_CHANGES))
34 		return;
35 
36 	BMessage message(MSG_CONTROLLER_FILE_FINISHED);
37 
38 	DeliverMessage(message);
39 }
40 
41 
42 void
43 ControllerObserver::FileChanged(PlaylistItem* item, status_t result)
44 {
45 	if (!(fObserveFlags & OBSERVE_FILE_CHANGES))
46 		return;
47 
48 	PlaylistItemRef reference(item);
49 		// pass the reference along with the message
50 
51 	BMessage message(MSG_CONTROLLER_FILE_CHANGED);
52 	message.AddInt32("result", result);
53 	if (message.AddPointer("item", item) == B_OK)
54 		reference.Detach();
55 
56 	DeliverMessage(message);
57 }
58 
59 
60 void
61 ControllerObserver::VideoTrackChanged(int32 index)
62 {
63 	if (!(fObserveFlags & OBSERVE_TRACK_CHANGES))
64 		return;
65 
66 	BMessage message(MSG_CONTROLLER_VIDEO_TRACK_CHANGED);
67 	message.AddInt32("index", index);
68 
69 	DeliverMessage(message);
70 }
71 
72 
73 void
74 ControllerObserver::AudioTrackChanged(int32 index)
75 {
76 	if (!(fObserveFlags & OBSERVE_TRACK_CHANGES))
77 		return;
78 
79 	BMessage message(MSG_CONTROLLER_AUDIO_TRACK_CHANGED);
80 	message.AddInt32("index", index);
81 
82 	DeliverMessage(message);
83 }
84 
85 
86 void
87 ControllerObserver::SubTitleTrackChanged(int32 index)
88 {
89 	if (!(fObserveFlags & OBSERVE_TRACK_CHANGES))
90 		return;
91 
92 	BMessage message(MSG_CONTROLLER_SUB_TITLE_TRACK_CHANGED);
93 	message.AddInt32("index", index);
94 
95 	DeliverMessage(message);
96 }
97 
98 
99 void
100 ControllerObserver::VideoStatsChanged()
101 {
102 	if (!(fObserveFlags & OBSERVE_STAT_CHANGES))
103 		return;
104 
105 	BMessage message(MSG_CONTROLLER_VIDEO_STATS_CHANGED);
106 
107 	DeliverMessage(message);
108 }
109 
110 
111 void
112 ControllerObserver::AudioStatsChanged()
113 {
114 	if (!(fObserveFlags & OBSERVE_STAT_CHANGES))
115 		return;
116 
117 	BMessage message(MSG_CONTROLLER_AUDIO_STATS_CHANGED);
118 
119 	DeliverMessage(message);
120 }
121 
122 
123 void
124 ControllerObserver::PlaybackStateChanged(uint32 state)
125 {
126 	if (!(fObserveFlags & OBSERVE_PLAYBACK_STATE_CHANGES))
127 		return;
128 
129 	BMessage message(MSG_CONTROLLER_PLAYBACK_STATE_CHANGED);
130 	message.AddInt32("state", state);
131 
132 	DeliverMessage(message);
133 }
134 
135 
136 void
137 ControllerObserver::PositionChanged(float position)
138 {
139 	if (!(fObserveFlags & OBSERVE_POSITION_CHANGES))
140 		return;
141 
142 	BMessage message(MSG_CONTROLLER_POSITION_CHANGED);
143 	message.AddFloat("position", position);
144 
145 	DeliverMessage(message);
146 }
147 
148 
149 void
150 ControllerObserver::SeekHandled(int64 seekFrame)
151 {
152 	if (!(fObserveFlags & OBSERVE_POSITION_CHANGES))
153 		return;
154 
155 	BMessage message(MSG_CONTROLLER_SEEK_HANDLED);
156 	message.AddInt64("seek frame", seekFrame);
157 
158 	DeliverMessage(message);
159 }
160 
161 
162 void
163 ControllerObserver::VolumeChanged(float volume)
164 {
165 	if (!(fObserveFlags & OBSERVE_VOLUME_CHANGES))
166 		return;
167 
168 	BMessage message(MSG_CONTROLLER_VOLUME_CHANGED);
169 	message.AddFloat("volume", volume);
170 
171 	DeliverMessage(message);
172 }
173 
174 
175 void
176 ControllerObserver::MutedChanged(bool muted)
177 {
178 	if (!(fObserveFlags & OBSERVE_VOLUME_CHANGES))
179 		return;
180 
181 	BMessage message(MSG_CONTROLLER_MUTED_CHANGED);
182 	message.AddBool("muted", muted);
183 
184 	DeliverMessage(message);
185 }
186