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 fPlaybackFailed(false) 36 { 37 #ifdef DEBUG_INSTANCE_COUNT 38 atomic_add(&sInstanceCount, 1); 39 printf("%p->PlaylistItem::PlaylistItem() (%ld)\n", this, sInstanceCount); 40 #endif 41 } 42 43 44 PlaylistItem::~PlaylistItem() 45 { 46 #ifdef DEBUG_INSTANCE_COUNT 47 atomic_add(&sInstanceCount, -1); 48 printf("%p->PlaylistItem::~PlaylistItem() (%ld)\n", this, sInstanceCount); 49 #endif 50 } 51 52 53 BString 54 PlaylistItem::Name() const 55 { 56 BString name; 57 if (GetAttribute(ATTR_STRING_NAME, name) != B_OK) 58 name = "<unnamed>"; 59 return name; 60 } 61 62 63 BString 64 PlaylistItem::Author() const 65 { 66 BString author; 67 if (GetAttribute(ATTR_STRING_AUTHOR, author) != B_OK) 68 author = "<unknown>"; 69 return author; 70 } 71 72 73 BString 74 PlaylistItem::Album() const 75 { 76 BString album; 77 if (GetAttribute(ATTR_STRING_ALBUM, album) != B_OK) 78 album = "<unknown>"; 79 return album; 80 } 81 82 83 BString 84 PlaylistItem::Title() const 85 { 86 BString title; 87 if (GetAttribute(ATTR_STRING_TITLE, title) != B_OK) 88 title = "<untitled>"; 89 return title; 90 } 91 92 93 int32 94 PlaylistItem::TrackNumber() const 95 { 96 int32 trackNumber; 97 if (GetAttribute(ATTR_INT32_TRACK, trackNumber) != B_OK) 98 trackNumber = 0; 99 return trackNumber; 100 } 101 102 103 int32 104 PlaylistItem::BitRate() const 105 { 106 int32 bitrate; 107 if (GetAttribute(ATTR_INT32_BIT_RATE, bitrate) != B_OK) 108 bitrate = 0; 109 return bitrate; 110 } 111 112 113 bigtime_t 114 PlaylistItem::Duration() const 115 { 116 bigtime_t duration; 117 if (GetAttribute(ATTR_INT64_DURATION, duration) != B_OK) 118 duration = 0; 119 return duration; 120 } 121 122 123 void 124 PlaylistItem::SetPlaybackFailed() 125 { 126 fPlaybackFailed = true; 127 } 128 129 130 //! You must hold the Playlist lock. 131 bool 132 PlaylistItem::AddListener(Listener* listener) 133 { 134 if (listener && !fListeners.HasItem(listener)) 135 return fListeners.AddItem(listener); 136 return false; 137 } 138 139 140 //! You must hold the Playlist lock. 141 void 142 PlaylistItem::RemoveListener(Listener* listener) 143 { 144 fListeners.RemoveItem(listener); 145 } 146 147 148 void 149 PlaylistItem::_NotifyListeners() const 150 { 151 BList listeners(fListeners); 152 int32 count = listeners.CountItems(); 153 for (int32 i = 0; i < count; i++) { 154 Listener* listener = (Listener*)listeners.ItemAtFast(i); 155 listener->ItemChanged(this); 156 } 157 } 158 159