Skip to content

Commit 00d6a42

Browse files
committed
fix
1 parent 96b2bf4 commit 00d6a42

11 files changed

Lines changed: 110 additions & 76 deletions

src/PlayerEngine.mm

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ -(void)needResumePlayAtBoot
3131
PlayerDocument *doc = player().document;
3232
if (doc.resumeAtReboot && doc.playState != playstate_stopped )
3333
{
34-
PlayerTrack *track = player().playing;
34+
PlayerTrack *track = Playing();
3535
PlayerList *list = track.list;
3636

3737
if ( doc.playState == playstate_playing )
@@ -112,14 +112,14 @@ -(void)DidPlayToEndTime:(NSNotification*)n
112112
postEvent(EventID_track_stopped_playnext, nil);
113113

114114
if( player().document.trackSongsWhenPlayStarted)
115-
postEvent(EventID_to_reload_tracklist, player().playing);
115+
postEvent(EventID_to_reload_tracklist, Playing());
116116
}
117117

118118
// action by user.
119119
-(void)actionPlayNext
120120
{
121121
[self playNext];
122-
PlayerTrack *track = player().playing;
122+
PlayerTrack *track = Playing();
123123
postEvent(EventID_to_reload_tracklist, track );
124124
}
125125

@@ -135,7 +135,7 @@ -(void)playNext
135135
}
136136
else
137137
{
138-
PlayerTrack *track = player().playing;
138+
PlayerTrack *track = Playing();
139139
PlayerList *list = track.list;
140140

141141
assert(list);
@@ -233,12 +233,12 @@ -(void)actionPlayRandom
233233
{
234234
PlayerDocument *d = player().document;
235235

236-
PlayerTrack *track = player().playing;
236+
PlayerTrack *track = Playing();
237237

238-
PlayerList *list = track.list;
238+
const PlayerList *list = track.list;
239239

240240
if (!list)
241-
list = d.playerlList.selectItem ;
241+
list = [d.playerlList getSelectedItem] ;
242242

243243
assert(list);
244244

@@ -339,7 +339,7 @@ -(void)stop
339339
[_player pause];
340340
[_player replaceCurrentItemWithPlayerItem:nil];
341341

342-
player().playing = nil;
342+
setPlaying(nil);
343343

344344
postEvent(EventID_track_stopped, nil);
345345
postEvent(EventID_track_state_changed, nil);

src/PlayerImpl.mm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ -(void)playTrackInfo:(PlayerTrack*)track pauseAfterInit:(BOOL)pfi
9595

9696
if ([[NSFileManager defaultManager] fileExistsAtPath: path])
9797
{
98-
player().playing = track;
98+
setPlaying(track);
9999
[self playURL:[NSURL fileURLWithPath: path] pauseAfterInit:pfi];
100100
}
101101
else
@@ -109,7 +109,7 @@ void playTrack(PlayerTrack *track)
109109
{
110110
if (track)
111111
{
112-
player().playing = track;
112+
setPlaying(track);
113113

114114
[player().engine playTrackInfo:track pauseAfterInit: FALSE ];
115115

@@ -141,7 +141,7 @@ @implementation PlayerDocument (documentLoaded)
141141

142142
-(void)willSaveConfig
143143
{
144-
PlayerTrack *track = player().playing;
144+
PlayerTrack *track = Playing();
145145
self.playingIndexTrack = (int)track.index;
146146
self.playingIndexList = (int)[player().document.playerlList getIndex: track.list];
147147
}
@@ -151,7 +151,7 @@ -(void)didLoad
151151
[self.playerlList didLoad];
152152

153153
if (self.playingIndexList >= 0 && self.playingIndexTrack >= 0)
154-
player().playing = [[self.playerlList getItem: self.playingIndexList] getItem: self.playingIndexTrack];
154+
setPlaying( [[self.playerlList getItem: self.playingIndexList] getItem: self.playingIndexTrack]);
155155

156156
}
157157

@@ -161,7 +161,7 @@ @implementation PlayerlList (documentLoaded)
161161

162162
-(void)willSave
163163
{
164-
self.selectIndex = (int) [self getIndex:self.selectItem];
164+
self.selectIndex = (int) [self getIndex:(PlayerList*) [self getSelectedItem]];
165165
}
166166

167167
-(void)didLoad

src/PlayerList.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,16 @@
6767

6868
/// use selectItem at application's runtime. selectIndex when serialize.
6969
@property (nonatomic) int selectIndex;
70-
@property (nonatomic) PlayerList *selectItem;
71-
70+
-(void)setSelectItem:(PlayerList*)list;
71+
-(const PlayerList*)getSelectedItem;
7272

7373
@property (nonatomic,strong) NSMutableArray *playerlList;
7474

7575
-(PlayerList*)getItem:(int)index;
7676

7777
-(NSInteger)getIndex:(PlayerList*)list;
7878

79-
//-(void)setSelectItem:(PlayerList*)list;
80-
//-(PlayerList*)getSelectedList;
79+
8180

8281
-(size_t)count;
8382

src/PlayerList.mm

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ @interface PlayerList()
2121

2222
@implementation PlayerList
2323

24+
-(void)setName:(NSString *)name
25+
{
26+
_name = name;
27+
_isDirty = TRUE;
28+
}
29+
30+
-(void)setType:(enum PlayerListType)type
31+
{
32+
_type = type;
33+
_isDirty = TRUE;
34+
}
35+
2436
const char fileformat[] = "%08d.plist";
2537

2638
+(instancetype)instanceFromFileIndex:(int)index
@@ -75,13 +87,14 @@ -(instancetype)initWithCoder:(NSCoder *)aDecoder
7587
track.list = self;
7688
}
7789

90+
self.isDirty = FALSE;
7891
}
7992
else
8093
{
94+
self.isDirty = TRUE;
8195
postEvent(EventID_play_error_happened, [PlayerError errorConfigVersionDismatch]);
8296
}
83-
84-
self.isDirty = FALSE;
97+
8598

8699
self.fileIndex = -1;
87100
}
@@ -263,11 +276,22 @@ -(int)indexInParent
263276

264277
@interface PlayerlList ()
265278
@property (nonatomic,strong) PlayerList *tempPlayerlist;
279+
@property (nonatomic) PlayerList *selectItem;
266280
@end
267281

268282

269283
@implementation PlayerlList
270284

285+
-(void)setSelectItem:(PlayerList*)list
286+
{
287+
_selectItem = list;
288+
}
289+
290+
-(const PlayerList*)getSelectedItem
291+
{
292+
return _selectItem;
293+
}
294+
271295
-(instancetype)initWithCoder:(NSCoder *)aDecoder
272296
{
273297
if (self = [super init]) {

src/PlayerSerachMng.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
@interface PlayerSearchMng : NSObject
17-
@property (nonatomic,strong) PlayerList *playerlistOriginal,*playerlistFilter;
17+
@property (nonatomic,strong) const PlayerList *playerlistOriginal,*playerlistFilter;
1818
@property (nonatomic,strong) NSMutableDictionary *dicFilterToOrginal;//index
1919

2020
-(void)search:(NSString*)key;

src/UPlayer.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@
2626
-(void)save;
2727
-(void)load;
2828

29-
@property (nonatomic,strong) PlayerTrack *playing;
3029
@end
3130

31+
32+
PlayerTrack* Playing();
33+
void setPlaying(PlayerTrack* p);
34+
35+
3236
@interface PlayerEngine (playTrack)
3337
-(void)playTrackInfo:(PlayerTrack*)track pauseAfterInit:(BOOL)pfi;
3438
@end

src/UPlayer.mm

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ -(instancetype)init
3838
self = [super init];
3939
if (self)
4040
{
41-
42-
self.document = [[PlayerDocument alloc ] init];
41+
[self load];
42+
// self.document = [[PlayerDocument alloc ] init];
4343

4444
self.layout= [[PlayerLayout alloc] init];
4545
self.engine= [[PlayerEngine alloc] init];
@@ -102,3 +102,16 @@ -(void)cmdSaveUILayout
102102
{
103103
return _player?_player:(_player=[[UPlayer alloc]init]);
104104
}
105+
106+
107+
static PlayerTrack *playing = nil;
108+
109+
PlayerTrack* Playing()
110+
{
111+
return playing;
112+
}
113+
114+
void setPlaying(PlayerTrack* p)
115+
{
116+
playing = p;
117+
}

uPlayer/AppDelegate.mm

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,22 @@ -(instancetype)init
5656
// Add observers
5757
[self addObservers];
5858

59-
60-
6159
// Load ui layout
6260
[player().layout load];
6361

6462
[self setUpHotkeys];
6563

66-
6764
// Load and maintain main window controller
6865
NSStoryboard *storyboard = [NSStoryboard storyboardWithName:@"Main" bundle:nil];
6966

7067
self.mainWindowController = [storyboard instantiateControllerWithIdentifier:@"IDMainWindow"];
7168

72-
7369
[self setUpStatusBar];
7470

7571
// Load document and notify the window
7672
[self loadDocument];
77-
7873

7974
[_mainWindowController showWindow:nil];
80-
8175
}
8276

8377
return self;
@@ -163,7 +157,7 @@ - (IBAction)cmdOpenDirectory:(id)sender
163157
NSString* fileName =[(NSURL*)(files.firstObject) path];
164158

165159
PlayerDocument *document = player().document;
166-
PlayerList *list = document.playerlList.selectItem;
160+
const PlayerList *list = [document.playerlList getSelectedItem];
167161

168162
dojobInBkgnd(
169163
^{
@@ -182,7 +176,7 @@ - (IBAction)cmdOpenDirectory:(id)sender
182176

183177
-(void)reloadiTunesMedia
184178
{
185-
PlayerList *selected = player().document.playerlList.selectItem;
179+
const PlayerList *selected = [player().document.playerlList getSelectedItem];
186180
[selected removeAll];
187181
postEvent(EventID_to_reload_tracklist, selected);
188182

@@ -237,21 +231,21 @@ - (IBAction)cmdPrevPlaylist:(id)sender
237231
{
238232
PlayerlList *llist = player().document.playerlList;
239233

240-
PlayerList *currList = llist.selectItem;
234+
const PlayerList *currList = [llist getSelectedItem];
241235

242-
PlayerList *prevList = [llist getPreviousItem: [llist getIndex:currList]];
236+
PlayerList *prevList = [llist getPreviousItem: [llist getIndex: (PlayerList*)currList]];
243237

244238
if(prevList)
245239
postEvent(EventID_to_reload_playlist, prevList);
246240
}
247241

248242
- (IBAction)cmdNextPlaylist:(id)sender
249243
{
250-
PlayerlList *llist = player().document.playerlList;
244+
PlayerlList *llist = player().document.playerlList;
251245

252-
PlayerList *currList = llist.selectItem;
246+
const PlayerList *currList = [llist getSelectedItem];
253247

254-
PlayerList *nextList = [llist getNextItem: [llist getIndex:currList]];
248+
PlayerList *nextList = [llist getNextItem: [llist getIndex:(PlayerList*)currList]];
255249

256250
if(nextList)
257251
postEvent(EventID_to_reload_playlist, nextList);
@@ -326,7 +320,7 @@ -(void)loadDocument
326320
{
327321
PlayerDocument *d = player().document;
328322

329-
[player() load];
323+
// [player() load];
330324
// if( [d load] )
331325
// {
332326
postEvent(EventID_to_reload_tracklist, nil);
@@ -378,7 +372,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
378372
[self cmdNewPlayerList:nil];
379373

380374
// add ~/music to a default playerlist, if is none.
381-
if ( [d.playerlList count] == 1 && d.playerlList.selectItem.count == 0)
375+
if ( [d.playerlList count] == 1 && [d.playerlList getSelectedItem].count == 0)
382376
{
383377
[self loadiTunesMedia];
384378
}
@@ -396,7 +390,7 @@ -(void)loadiTunesMedia
396390

397391
userMusic = [userMusic stringByAppendingPathComponent:@"iTunes/iTunes Media/Music"];
398392

399-
PlayerList *list = d.playerlList.selectItem;
393+
const PlayerList *list = [d.playerlList getSelectedItem];
400394

401395
dojobInBkgnd(
402396
^{
@@ -411,7 +405,7 @@ -(void)loadiTunesMedia
411405

412406
-(void)track_state_changed
413407
{
414-
PlayerTrack *track = player().playing;
408+
PlayerTrack *track = Playing();
415409

416410
BOOL stopped = [player().engine isStopped];
417411
BOOL paused = [player().engine isPaused];
@@ -486,7 +480,7 @@ -(void)scrobbler:(NSNotification*)n
486480
LFUser *user = lastFmUser();
487481
if (user->isConnected)
488482
{
489-
TrackInfo *info = player().playing.info;
483+
TrackInfo *info = Playing().info;
490484

491485
dojobInBkgnd(^{
492486
string artist(info.artist.UTF8String);
@@ -519,7 +513,7 @@ -(void)playerErrorHandler:(NSNotification*)n
519513

520514
-(BOOL)importDirectoryEnabled
521515
{
522-
return player().document.playerlList.selectItem.type != type_temporary ;
516+
return [player().document.playerlList getSelectedItem].type != type_temporary ;
523517
}
524518

525519

@@ -532,7 +526,7 @@ -(void)lastFm_loveTrack:(NSNotification*)n
532526
{
533527
PlayerTrack *track = n.object;
534528
if (track == nil)
535-
track = player().playing;
529+
track = Playing();
536530

537531
lastFm_loveTrack( track );
538532
}

uPlayer/PlaylistViewController.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ -(void)reloadTrackList
5252

5353
[self.tableView resignFirstResponder];
5454

55-
PlayerTrack *track = player().playing;
55+
PlayerTrack *track = Playing();
5656

5757
PlayerList *list = track.list;
5858

0 commit comments

Comments
 (0)