xref: /haiku/src/apps/mediaplayer/playlist/PlaylistItem.cpp (revision 893988af824e65e49e55f517b157db8386e8002b)
1 /*
2  * Copyright 2009 Stephan Aßmus <superstippi@gmx.de>
3  * All rights reserved. Distributed under the terms of the MIT license.
4  */
5 
6 #include "PlaylistItem.h"
7 
8 #include <stdio.h>
9 
10 
11 PlaylistItem::Listener::Listener()
12 {
13 }
14 
15 PlaylistItem::Listener::~Listener()
16 {
17 }
18 
19 void PlaylistItem::Listener::ItemChanged(const PlaylistItem* item)
20 {
21 }
22 
23 
24 // #pragma mark -
25 
26 
27 //#define DEBUG_INSTANCE_COUNT
28 #ifdef DEBUG_INSTANCE_COUNT
29 static vint32 sInstanceCount = 0;
30 #endif
31 
32 
33 PlaylistItem::PlaylistItem()
34 {
35 #ifdef DEBUG_INSTANCE_COUNT
36 	atomic_add(&sInstanceCount, 1);
37 	printf("%p->PlaylistItem::PlaylistItem() (%ld)\n", this, sInstanceCount);
38 #endif
39 }
40 
41 
42 PlaylistItem::~PlaylistItem()
43 {
44 #ifdef DEBUG_INSTANCE_COUNT
45 	atomic_add(&sInstanceCount, -1);
46 	printf("%p->PlaylistItem::~PlaylistItem() (%ld)\n", this, sInstanceCount);
47 #endif
48 }
49 
50 
51 BString
52 PlaylistItem::Name() const
53 {
54 	BString name;
55 	if (GetAttribute(ATTR_STRING_NAME, name) != B_OK)
56 		name = "<unnamed>";
57 	return name;
58 }
59 
60 
61 BString
62 PlaylistItem::Author() const
63 {
64 	BString author;
65 	if (GetAttribute(ATTR_STRING_AUTHOR, author) != B_OK)
66 		author = "<unknown>";
67 	return author;
68 }
69 
70 
71 BString
72 PlaylistItem::Album() const
73 {
74 	BString album;
75 	if (GetAttribute(ATTR_STRING_ALBUM, album) != B_OK)
76 		album = "<unknown>";
77 	return album;
78 }
79 
80 
81 BString
82 PlaylistItem::Title() const
83 {
84 	BString title;
85 	if (GetAttribute(ATTR_STRING_TITLE, title) != B_OK)
86 		title = "<untitled>";
87 	return title;
88 }
89 
90 
91 int32
92 PlaylistItem::TrackNumber() const
93 {
94 	int32 trackNumber;
95 	if (GetAttribute(ATTR_INT32_TRACK, trackNumber) != B_OK)
96 		trackNumber = 0;
97 	return trackNumber;
98 }
99 
100 
101 int32
102 PlaylistItem::BitRate() const
103 {
104 	int32 bitrate;
105 	if (GetAttribute(ATTR_INT32_BIT_RATE, bitrate) != B_OK)
106 		bitrate = 0;
107 	return bitrate;
108 }
109 
110 
111 bigtime_t
112 PlaylistItem::Duration() const
113 {
114 	bigtime_t duration;
115 	if (GetAttribute(ATTR_INT64_DURATION, duration) != B_OK)
116 		duration = 0;
117 	return duration;
118 }
119 
120 
121 //! You must hold the Playlist lock.
122 bool
123 PlaylistItem::AddListener(Listener* listener)
124 {
125 	if (listener && !fListeners.HasItem(listener))
126 		return fListeners.AddItem(listener);
127 	return false;
128 }
129 
130 
131 //! You must hold the Playlist lock.
132 void
133 PlaylistItem::RemoveListener(Listener* listener)
134 {
135 	fListeners.RemoveItem(listener);
136 }
137 
138 
139 void
140 PlaylistItem::_NotifyListeners() const
141 {
142 	BList listeners(fListeners);
143 	int32 count = listeners.CountItems();
144 	for (int32 i = 0; i < count; i++) {
145 		Listener* listener = (Listener*)listeners.ItemAtFast(i);
146 		listener->ItemChanged(this);
147 	}
148 }
149 
150