22
22
*/
23
23
24
24
#import " ReplayGainScannerController.h"
25
+ #import " Weakify.h"
26
+
25
27
#include " rg_scanner.h"
26
28
#include < sys/time.h>
27
29
@@ -163,16 +165,16 @@ - (void)runScanner:(int)mode forTracks:(DB_playItem_t **)tracks count:(int)count
163
165
[self progress: 0 ];
164
166
165
167
dispatch_queue_t aQueue = dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 );
166
- __weak ReplayGainScannerController *weakSelf = self;
168
+ weakify ( self) ;
167
169
dispatch_async (aQueue, ^{
168
- ReplayGainScannerController *strongSelf = weakSelf ;
170
+ strongify (self) ;
169
171
if (self == nil ) {
170
172
return ;
171
173
}
172
174
_rg->scan (&self->_rg_settings );
173
175
deadbeef->background_job_decrement ();
174
176
dispatch_async (dispatch_get_main_queue (), ^{
175
- if (strongSelf .abort_flag ) {
177
+ if (self .abort_flag ) {
176
178
[self dismissController: self ];
177
179
return ;
178
180
}
@@ -195,31 +197,31 @@ - (void)removeRgTagsFromTracks:(DB_playItem_t **)tracks count:(int)count {
195
197
_updateTagsProgressWindow.isVisible = YES ;
196
198
_abortTagWriting = NO ;
197
199
198
- __weak ReplayGainScannerController *weakSelf = self;
200
+ weakify ( self) ;
199
201
dispatch_queue_t aQueue = dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 );
200
202
dispatch_async (aQueue, ^{
201
- ReplayGainScannerController *strongSelf = weakSelf ;
202
- if (strongSelf == nil ) {
203
+ strongify (self) ;
204
+ if (self == nil ) {
203
205
return ;
204
206
}
205
- for (int i = 0 ; i < strongSelf ->_rg_settings .num_tracks ; i++) {
206
- _rg->remove (strongSelf ->_rg_settings .tracks [i]);
207
- if (strongSelf .abortTagWriting ) {
207
+ for (int i = 0 ; i < self ->_rg_settings .num_tracks ; i++) {
208
+ _rg->remove (self ->_rg_settings .tracks [i]);
209
+ if (self .abortTagWriting ) {
208
210
break ;
209
211
}
210
212
dispatch_async (dispatch_get_main_queue (), ^{
211
213
// progress
212
214
deadbeef->pl_lock ();
213
- NSString *path = @(deadbeef->pl_find_meta_raw (strongSelf ->_rg_settings .tracks [i], " :URI" ));
215
+ NSString *path = @(deadbeef->pl_find_meta_raw (self ->_rg_settings .tracks [i], " :URI" ));
214
216
deadbeef->pl_unlock ();
215
- strongSelf .updateTagsProgressText .stringValue = path;
216
- strongSelf .updateTagsProgressIndicator .doubleValue = (double )i/strongSelf ->_rg_settings .num_tracks *100 ;
217
+ self .updateTagsProgressText .stringValue = path;
218
+ self .updateTagsProgressIndicator .doubleValue = (double )i/self ->_rg_settings .num_tracks *100 ;
217
219
});
218
220
}
219
221
deadbeef->pl_save_all ();
220
222
deadbeef->background_job_decrement ();
221
223
dispatch_async (dispatch_get_main_queue (), ^{
222
- [strongSelf .updateTagsProgressWindow close ];
224
+ [self .updateTagsProgressWindow close ];
223
225
[self dismissController: self ];
224
226
});
225
227
});
@@ -299,38 +301,38 @@ - (IBAction)updateFileTagsAction:(id)sender {
299
301
_abortTagWriting = NO ;
300
302
dispatch_queue_t aQueue = dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 );
301
303
302
- __weak ReplayGainScannerController *weakSelf = self;
304
+ weakify ( self) ;
303
305
304
306
dispatch_async (aQueue, ^{
305
- ReplayGainScannerController *strongSelf = weakSelf ;
306
- if (strongSelf == nil ) {
307
+ strongify (self) ;
308
+ if (self == nil ) {
307
309
return ;
308
310
}
309
- for (int i = 0 ; i < strongSelf ->_rg_settings .num_tracks ; i++) {
310
- if (strongSelf .abortTagWriting ) {
311
+ for (int i = 0 ; i < self ->_rg_settings .num_tracks ; i++) {
312
+ if (self .abortTagWriting ) {
311
313
break ;
312
314
}
313
315
314
- if (strongSelf ->_rg_settings .results [i].scan_result == DDB_RG_SCAN_RESULT_SUCCESS) {
316
+ if (self ->_rg_settings .results [i].scan_result == DDB_RG_SCAN_RESULT_SUCCESS) {
315
317
deadbeef->pl_lock ();
316
- NSString *path = @(deadbeef->pl_find_meta_raw (strongSelf ->_rg_settings .tracks [i], " :URI" ));
318
+ NSString *path = @(deadbeef->pl_find_meta_raw (self ->_rg_settings .tracks [i], " :URI" ));
317
319
deadbeef->pl_unlock ();
318
320
dispatch_async (dispatch_get_main_queue (), ^{
319
- strongSelf .updateTagsProgressText .stringValue = path;
320
- strongSelf .updateTagsProgressIndicator .doubleValue = (double )i/strongSelf ->_rg_settings .num_tracks *100 ;
321
+ self .updateTagsProgressText .stringValue = path;
322
+ self .updateTagsProgressIndicator .doubleValue = (double )i/self ->_rg_settings .num_tracks *100 ;
321
323
});
322
324
323
325
uint32_t flags = (1 <<DDB_REPLAYGAIN_TRACKGAIN)|(1 <<DDB_REPLAYGAIN_TRACKPEAK);
324
- if (strongSelf ->_rg_settings .mode != DDB_RG_SCAN_MODE_TRACK) {
326
+ if (self ->_rg_settings .mode != DDB_RG_SCAN_MODE_TRACK) {
325
327
flags |= (1 <<DDB_REPLAYGAIN_ALBUMGAIN)|(1 <<DDB_REPLAYGAIN_ALBUMPEAK);
326
328
}
327
- _rg->apply (strongSelf ->_rg_settings .tracks [i], flags, strongSelf ->_rg_settings .results [i].track_gain , strongSelf ->_rg_settings .results [i].track_peak , strongSelf ->_rg_settings .results [i].album_gain , strongSelf ->_rg_settings .results [i].album_peak );
329
+ _rg->apply (self ->_rg_settings .tracks [i], flags, self ->_rg_settings .results [i].track_gain , self ->_rg_settings .results [i].track_peak , self ->_rg_settings .results [i].album_gain , self ->_rg_settings .results [i].album_peak );
328
330
}
329
331
}
330
332
deadbeef->pl_save_all ();
331
333
332
334
dispatch_async (dispatch_get_main_queue (), ^{
333
- [self .window endSheet: strongSelf .updateTagsProgressWindow returnCode: NSModalResponseOK ];
335
+ [self .window endSheet: self .updateTagsProgressWindow returnCode: NSModalResponseOK ];
334
336
[self dismissController: self ];
335
337
});
336
338
});
0 commit comments