/
MainWindowController.cs
855 lines (719 loc) · 38.3 KB
/
MainWindowController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
// Copyright © 2011-2013 Yanick Castonguay
//
// This file is part of MPfm.
//
// MPfm is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// MPfm is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using MonoMac.AppKit;
using MonoMac.CoreGraphics;
using MonoMac.CoreText;
using MonoMac.Foundation;
using MPfm.Core;
using MPfm.Library;
using MPfm.MVP;
using MPfm.Sound;
using MPfm.MVP.Views;
using MPfm.MVP.Models;
using MPfm.Sound.AudioFiles;
using MPfm.Library.UpdateLibrary;
using MPfm.MVP.Messages;
using MPfm.Mac.Classes.Objects;
using MPfm.Mac.Classes.Helpers;
using MPfm.Mac.Classes.Delegates;
using MPfm.Player.Objects;
using MPfm.MVP.Presenters;
namespace MPfm.Mac
{
/// <summary>
/// Main window controller.
/// </summary>
public partial class MainWindowController : BaseWindowController, IMainView
{
List<Marker> _markers = new List<Marker>();
LibraryBrowserOutlineViewDelegate _libraryBrowserOutlineViewDelegate = null;
LibraryBrowserDataSource _libraryBrowserDataSource = null;
SongBrowserTableViewDelegate _songBrowserOutlineViewDelegate = null;
SongBrowserSource _songBrowserSource = null;
AlbumCoverSource _albumCoverSource = null;
AlbumCoverCacheService _albumCoverCacheService = null;
public MainWindowController(IntPtr handle)
: base (handle)
{
}
public MainWindowController(Action<IBaseView> onViewReady) : base ("MainWindow", onViewReady)
{
this._albumCoverCacheService = new AlbumCoverCacheService();
this.Window.AlphaValue = 0;
this.Window.MakeKeyAndOrderFront(this);
// Fade in main window
NSMutableDictionary dict = new NSMutableDictionary();
dict.Add(NSViewAnimation.TargetKey, Window);
dict.Add(NSViewAnimation.EffectKey, NSViewAnimation.FadeInEffect);
NSViewAnimation anim = new NSViewAnimation(new List<NSMutableDictionary>(){ dict }.ToArray());
anim.Duration = 0.4f;
anim.StartAnimation();
}
public override void WindowDidLoad()
{
base.WindowDidLoad();
Tracing.Log("MainWindowController.WindowDidLoad -- Initializing user interface...");
//this.Window.Title = "Sessions " + Assembly.GetExecutingAssembly().GetName().Version.ToString() + " ALPHA";
splitMain.Delegate = new MainSplitViewDelegate();
cboSoundFormat.RemoveAllItems();
cboSoundFormat.AddItem("All");
cboSoundFormat.AddItem("FLAC");
cboSoundFormat.AddItem("OGG");
cboSoundFormat.AddItem("MP3");
cboSoundFormat.AddItem("MPC");
cboSoundFormat.AddItem("WAV");
cboSoundFormat.AddItem("WV");
_libraryBrowserOutlineViewDelegate = new LibraryBrowserOutlineViewDelegate((entity) => { OnTreeNodeSelected(entity); });
outlineLibraryBrowser.Delegate = _libraryBrowserOutlineViewDelegate;
outlineLibraryBrowser.AllowsMultipleSelection = false;
outlineLibraryBrowser.DoubleClick += HandleLibraryBrowserDoubleClick;
_songBrowserOutlineViewDelegate = new SongBrowserTableViewDelegate();
tableSongBrowser.Delegate = _songBrowserOutlineViewDelegate;
tableSongBrowser.AllowsMultipleSelection = true;
tableSongBrowser.DoubleClick += HandleSongBrowserDoubleClick;
tableMarkers.WeakDelegate = this;
tableMarkers.WeakDataSource = this;
tableMarkers.DoubleClick += HandleMarkersDoubleClick;
LoadImages();
SetTheme();
tableAlbumCovers.FocusRingType = NSFocusRingType.None;
tableSongBrowser.FocusRingType = NSFocusRingType.None;
scrollViewSongBrowser.BorderType = NSBorderType.NoBorder;
scrollViewAlbumCovers.BorderType = NSBorderType.NoBorder;
scrollViewAlbumCovers.HasHorizontalScroller = false;
scrollViewAlbumCovers.HasVerticalScroller = false;
scrollViewAlbumCovers.SetSynchronizedScrollView(scrollViewSongBrowser);
scrollViewSongBrowser.SetSynchronizedScrollView(scrollViewAlbumCovers);
NSNotificationCenter.DefaultCenter.AddObserver(new NSString("NSOutlineViewItemDidExpandNotification"), ItemDidExpand, outlineLibraryBrowser);
OnViewReady.Invoke(this);
}
private void SetTheme()
{
viewLeftHeader.BackgroundColor1 = GlobalTheme.PanelHeaderColor1;
viewLeftHeader.BackgroundColor2 = GlobalTheme.PanelHeaderColor2;
viewRightHeader.BackgroundColor1 = GlobalTheme.PanelHeaderColor1;
viewRightHeader.BackgroundColor2 = GlobalTheme.PanelHeaderColor2;
viewLoopsHeader.BackgroundColor1 = GlobalTheme.PanelHeaderColor1;
viewLoopsHeader.BackgroundColor2 = GlobalTheme.PanelHeaderColor2;
viewMarkersHeader.BackgroundColor1 = GlobalTheme.PanelHeaderColor1;
viewMarkersHeader.BackgroundColor2 = GlobalTheme.PanelHeaderColor2;
viewSongBrowserHeader.BackgroundColor1 = GlobalTheme.PanelHeaderColor1;
viewSongBrowserHeader.BackgroundColor2 = GlobalTheme.PanelHeaderColor2;
btnPlayLoop.BackgroundColor = GlobalTheme.ButtonToolbarBackgroundColor;
btnPlayLoop.BackgroundMouseOverColor = GlobalTheme.ButtonToolbarBackgroundMouseOverColor;
btnPlayLoop.BackgroundMouseDownColor = GlobalTheme.ButtonToolbarBackgroundMouseDownColor;
btnPlayLoop.BorderColor = GlobalTheme.ButtonToolbarBorderColor;
btnStopLoop.BackgroundColor = GlobalTheme.ButtonToolbarBackgroundColor;
btnStopLoop.BackgroundMouseOverColor = GlobalTheme.ButtonToolbarBackgroundMouseOverColor;
btnStopLoop.BackgroundMouseDownColor = GlobalTheme.ButtonToolbarBackgroundMouseDownColor;
btnStopLoop.BorderColor = GlobalTheme.ButtonToolbarBorderColor;
btnAddLoop.BackgroundColor = GlobalTheme.ButtonToolbarBackgroundColor;
btnAddLoop.BackgroundMouseOverColor = GlobalTheme.ButtonToolbarBackgroundMouseOverColor;
btnAddLoop.BorderColor = GlobalTheme.ButtonToolbarBorderColor;
btnAddLoop.BackgroundMouseDownColor = GlobalTheme.ButtonToolbarBackgroundMouseDownColor;
btnEditLoop.BackgroundColor = GlobalTheme.ButtonToolbarBackgroundColor;
btnEditLoop.BackgroundMouseOverColor = GlobalTheme.ButtonToolbarBackgroundMouseOverColor;
btnEditLoop.BackgroundMouseDownColor = GlobalTheme.ButtonToolbarBackgroundMouseDownColor;
btnEditLoop.BorderColor = GlobalTheme.ButtonToolbarBorderColor;
btnRemoveLoop.BackgroundColor = GlobalTheme.ButtonToolbarBackgroundColor;
btnRemoveLoop.BackgroundMouseOverColor = GlobalTheme.ButtonToolbarBackgroundMouseOverColor;
btnRemoveLoop.BackgroundMouseDownColor = GlobalTheme.ButtonToolbarBackgroundMouseDownColor;
btnRemoveLoop.BorderColor = GlobalTheme.ButtonToolbarBorderColor;
btnGoToMarker.BackgroundColor = GlobalTheme.ButtonToolbarBackgroundColor;
btnGoToMarker.BackgroundMouseOverColor = GlobalTheme.ButtonToolbarBackgroundMouseOverColor;
btnGoToMarker.BackgroundMouseDownColor = GlobalTheme.ButtonToolbarBackgroundMouseDownColor;
btnGoToMarker.BorderColor = GlobalTheme.ButtonToolbarBorderColor;
btnAddMarker.BackgroundColor = GlobalTheme.ButtonToolbarBackgroundColor;
btnAddMarker.BackgroundMouseOverColor = GlobalTheme.ButtonToolbarBackgroundMouseOverColor;
btnAddMarker.BackgroundMouseDownColor = GlobalTheme.ButtonToolbarBackgroundMouseDownColor;
btnAddMarker.BorderColor = GlobalTheme.ButtonToolbarBorderColor;
btnEditMarker.BackgroundColor = GlobalTheme.ButtonToolbarBackgroundColor;
btnEditMarker.BackgroundMouseOverColor = GlobalTheme.ButtonToolbarBackgroundMouseOverColor;
btnEditMarker.BackgroundMouseDownColor = GlobalTheme.ButtonToolbarBackgroundMouseDownColor;
btnEditMarker.BorderColor = GlobalTheme.ButtonToolbarBorderColor;
btnRemoveMarker.BackgroundColor = GlobalTheme.ButtonToolbarBackgroundColor;
btnRemoveMarker.BackgroundMouseOverColor = GlobalTheme.ButtonToolbarBackgroundMouseOverColor;
btnRemoveMarker.BackgroundMouseDownColor = GlobalTheme.ButtonToolbarBackgroundMouseDownColor;
btnRemoveMarker.BorderColor = GlobalTheme.ButtonToolbarBorderColor;
lblAlbumTitle.TextColor = NSColor.FromDeviceRgba(196f/255f, 213f/255f, 225f/255f, 1);
lblSongTitle.TextColor = NSColor.FromDeviceRgba(171f/255f, 186f/255f, 196f/255f, 1);
lblSongPath.TextColor = NSColor.FromDeviceRgba(97f/255f, 122f/255f, 140f/255f, 1);
viewInformation.IsHeaderVisible = true;
viewSongPosition.IsHeaderVisible = true;
viewVolume.IsHeaderVisible = true;
viewTimeShifting.IsHeaderVisible = true;
viewPitchShifting.IsHeaderVisible = true;
lblArtistName.Font = NSFont.FromFontName("TitilliumText25L-800wt", 24);
lblAlbumTitle.Font = NSFont.FromFontName("TitilliumText25L-600wt", 20);
lblSongTitle.Font = NSFont.FromFontName("TitilliumText25L-600wt", 17);
lblSongPath.Font = NSFont.FromFontName("TitilliumText25L-400wt", 12);
lblSampleRate.Font = NSFont.FromFontName("Junction", 11f);
lblBitrate.Font = NSFont.FromFontName("Junction", 11f);
lblFileType.Font = NSFont.FromFontName("Junction", 11f);
lblBitsPerSample.Font = NSFont.FromFontName("Junction", 11f);
lblFilterBySoundFormat.Font = NSFont.FromFontName("Junction", 11f);
lblTitleLibraryBrowser.Font = NSFont.FromFontName("TitilliumText25L-800wt", 14);
lblTitleCurrentSong.Font = NSFont.FromFontName("TitilliumText25L-800wt", 14);
lblTitleLoops.Font = NSFont.FromFontName("TitilliumText25L-800wt", 14);
lblTitleMarkers.Font = NSFont.FromFontName("TitilliumText25L-800wt", 14);
lblTitleSongBrowser.Font = NSFont.FromFontName("TitilliumText25L-800wt", 14);
lblSubtitleSongPosition.Font = NSFont.FromFontName("TitilliumText25L-800wt", 12);
lblSubtitleTimeShifting.Font = NSFont.FromFontName("TitilliumText25L-800wt", 12);
lblSubtitleVolume.Font = NSFont.FromFontName("TitilliumText25L-800wt", 12);
lblSubtitleInformation.Font = NSFont.FromFontName("TitilliumText25L-800wt", 12);
lblSubtitlePitchShifting.Font = NSFont.FromFontName("TitilliumText25L-800wt", 12);
lblPosition.Font = NSFont.FromFontName("DroidSansMono", 15f);
lblLength.Font = NSFont.FromFontName("DroidSansMono", 15f);
lblVolume.Font = NSFont.FromFontName("DroidSansMono", 11f);
txtPitchShiftingValue.Font = NSFont.FromFontName("DroidSansMono", 10f);
lblDetectedTempoValue.Font = NSFont.FromFontName("DroidSansMono", 10f);
lblReferenceTempoValue.Font = NSFont.FromFontName("DroidSansMono", 10f);
txtCurrentTempoValue.Font = NSFont.FromFontName("DroidSansMono", 10f);
lblDetectedTempo.Font = NSFont.FromFontName("Junction", 11);
lblCurrentTempo.Font = NSFont.FromFontName("Junction", 11);
lblReferenceTempo.Font = NSFont.FromFontName("Junction", 11);
lblSemitones.Font = NSFont.FromFontName("Junction", 11);
cboSoundFormat.Font = NSFont.FromFontName("Junction", 11);
searchSongBrowser.Font = NSFont.FromFontName("Junction", 12);
// Set cell fonts for Library Browser
NSTableColumn columnText = outlineLibraryBrowser.FindTableColumn(new NSString("columnText"));
columnText.DataCell.Font = NSFont.FromFontName("Junction", 11f);
// Set cell fonts for Song Browser
NSTableColumn columnTrackNumber = tableSongBrowser.FindTableColumn(new NSString("columnTrackNumber"));
NSTableColumn columnTitle = tableSongBrowser.FindTableColumn(new NSString("columnTitle"));
NSTableColumn columnLength = tableSongBrowser.FindTableColumn(new NSString("columnLength"));
NSTableColumn columnArtistName = tableSongBrowser.FindTableColumn(new NSString("columnArtistName"));
NSTableColumn columnAlbumTitle = tableSongBrowser.FindTableColumn(new NSString("columnAlbumTitle"));
columnTrackNumber.HeaderCell.Font = NSFont.FromFontName("Junction", 11f);
columnTrackNumber.DataCell.Font = NSFont.FromFontName("Junction", 11f);
columnTitle.HeaderCell.Font = NSFont.FromFontName("Junction", 11f);
columnTitle.DataCell.Font = NSFont.FromFontName("Junction", 11f);
columnLength.HeaderCell.Font = NSFont.FromFontName("Junction", 11f);
columnLength.DataCell.Font = NSFont.FromFontName("Junction", 11f);
columnArtistName.HeaderCell.Font = NSFont.FromFontName("Junction", 11f);
columnArtistName.DataCell.Font = NSFont.FromFontName("Junction", 11f);
columnAlbumTitle.HeaderCell.Font = NSFont.FromFontName("Junction", 11f);
columnAlbumTitle.DataCell.Font = NSFont.FromFontName("Junction", 11f);
// Set cell fonts for Loops
NSTableColumn columnLoopName = tableLoops.FindTableColumn(new NSString("columnLoopName"));
NSTableColumn columnLoopLength = tableLoops.FindTableColumn(new NSString("columnLoopLength"));
NSTableColumn columnLoopStartPosition = tableLoops.FindTableColumn(new NSString("columnLoopStartPosition"));
NSTableColumn columnLoopEndPosition = tableLoops.FindTableColumn(new NSString("columnLoopEndPosition"));
columnLoopName.HeaderCell.Font = NSFont.FromFontName("Junction", 11f);
columnLoopName.DataCell.Font = NSFont.FromFontName("Junction", 11f);
columnLoopLength.HeaderCell.Font = NSFont.FromFontName("Junction", 11f);
columnLoopLength.DataCell.Font = NSFont.FromFontName("Junction", 11f);
columnLoopStartPosition.HeaderCell.Font = NSFont.FromFontName("Junction", 11f);
columnLoopStartPosition.DataCell.Font = NSFont.FromFontName("Junction", 11f);
columnLoopEndPosition.HeaderCell.Font = NSFont.FromFontName("Junction", 11f);
columnLoopEndPosition.DataCell.Font = NSFont.FromFontName("Junction", 11f);
// Set cell fonts for Markers
NSTableColumn columnMarkerName = tableMarkers.FindTableColumn(new NSString("columnMarkerName"));
NSTableColumn columnMarkerPosition = tableMarkers.FindTableColumn(new NSString("columnMarkerPosition"));
NSTableColumn columnMarkerComments = tableMarkers.FindTableColumn(new NSString("columnMarkerComments"));
columnMarkerName.HeaderCell.Font = NSFont.FromFontName("Junction", 11f);
columnMarkerName.DataCell.Font = NSFont.FromFontName("Junction", 11f);
columnMarkerPosition.HeaderCell.Font = NSFont.FromFontName("Junction", 11f);
columnMarkerPosition.DataCell.Font = NSFont.FromFontName("Junction", 11f);
columnMarkerComments.HeaderCell.Font = NSFont.FromFontName("Junction", 11f);
columnMarkerComments.DataCell.Font = NSFont.FromFontName("Junction", 11f);
btnDetectTempo.Font = NSFont.FromFontName("Junction", 11f);
btnPlayLoop.Font = NSFont.FromFontName("Junction", 11f);
btnStopLoop.Font = NSFont.FromFontName("Junction", 11f);
btnAddLoop.Font = NSFont.FromFontName("Junction", 11f);
btnEditLoop.Font = NSFont.FromFontName("Junction", 11f);
btnRemoveLoop.Font = NSFont.FromFontName("Junction", 11f);
btnGoToMarker.Font = NSFont.FromFontName("Junction", 11f);
btnAddMarker.Font = NSFont.FromFontName("Junction", 11f);
btnEditMarker.Font = NSFont.FromFontName("Junction", 11f);
btnRemoveMarker.Font = NSFont.FromFontName("Junction", 11f);
}
/// <summary>
/// Loads the image resources in all controls.
/// </summary>
private void LoadImages()
{
// Load images in toolbar
toolbarMain.Items.FirstOrDefault(x => x.Identifier == "toolbarOpen").Image = ImageResources.images32x32.FirstOrDefault(x => x.Name == "32_icomoon_folder-open");
toolbarMain.Items.FirstOrDefault(x => x.Identifier == "toolbarUpdateLibrary").Image = ImageResources.images32x32.FirstOrDefault(x => x.Name == "32_icomoon_update");
toolbarMain.Items.FirstOrDefault(x => x.Identifier == "toolbarPlay").Image = ImageResources.images32x32.FirstOrDefault(x => x.Name == "32_icomoon_play");
//toolbarMain.Items.FirstOrDefault(x => x.Identifier == "toolbarPause").Image = ImageResources.images32x32.FirstOrDefault(x => x.Name == "32_icomoon_pause");
//toolbarMain.Items.FirstOrDefault(x => x.Identifier == "toolbarStop").Image = ImageResources.images32x32.FirstOrDefault(x => x.Name == "32_icomoon_stop");
toolbarMain.Items.FirstOrDefault(x => x.Identifier == "toolbarPrevious").Image = ImageResources.images32x32.FirstOrDefault(x => x.Name == "32_icomoon_previous");
toolbarMain.Items.FirstOrDefault(x => x.Identifier == "toolbarNext").Image = ImageResources.images32x32.FirstOrDefault(x => x.Name == "32_icomoon_next");
toolbarMain.Items.FirstOrDefault(x => x.Identifier == "toolbarRepeat").Image = ImageResources.images32x32.FirstOrDefault(x => x.Name == "32_icomoon_repeat");
toolbarMain.Items.FirstOrDefault(x => x.Identifier == "toolbarShuffle").Image = ImageResources.images32x32.FirstOrDefault(x => x.Name == "32_icomoon_repeat");
toolbarMain.Items.FirstOrDefault(x => x.Identifier == "toolbarEffects").Image = ImageResources.images32x32.FirstOrDefault(x => x.Name == "32_icomoon_equalizer");
toolbarMain.Items.FirstOrDefault(x => x.Identifier == "toolbarPlaylist").Image = ImageResources.images32x32.FirstOrDefault(x => x.Name == "32_icomoon_playlist");
toolbarMain.Items.FirstOrDefault(x => x.Identifier == "toolbarPreferences").Image = ImageResources.images32x32.FirstOrDefault(x => x.Name == "32_icomoon_settings");
toolbarMain.Items.FirstOrDefault(x => x.Identifier == "toolbarSync").Image = ImageResources.images32x32.FirstOrDefault(x => x.Name == "32_icomoon_sync");
// Load button images
cboSoundFormat.Image = ImageResources.images16x16.FirstOrDefault(x => x.Name == "16_icomoon_plus");
btnAddLoop.Image = ImageResources.images16x16.FirstOrDefault(x => x.Name == "16_icomoon_plus");
btnAddMarker.Image = ImageResources.images16x16.FirstOrDefault(x => x.Name == "16_icomoon_plus");
btnAddSongToPlaylist.Image = ImageResources.images16x16.FirstOrDefault(x => x.Name == "16_icomoon_plus");
btnEditLoop.Image = ImageResources.images16x16.FirstOrDefault(x => x.Name == "16_icomoon_quill");
btnEditMarker.Image = ImageResources.images16x16.FirstOrDefault(x => x.Name == "16_icomoon_quill");
btnEditSongMetadata.Image = ImageResources.images16x16.FirstOrDefault(x => x.Name == "16_icomoon_quill");
btnRemoveLoop.Image = ImageResources.images16x16.FirstOrDefault(x => x.Name == "16_icomoon_close");
btnRemoveMarker.Image = ImageResources.images16x16.FirstOrDefault(x => x.Name == "16_icomoon_close");
btnPlayLoop.Image = ImageResources.images16x16.FirstOrDefault(x => x.Name == "16_icomoon_play");
btnPlaySelectedSong.Image = ImageResources.images16x16.FirstOrDefault(x => x.Name == "16_icomoon_play");
btnStopLoop.Image = ImageResources.images16x16.FirstOrDefault(x => x.Name == "16_icomoon_stop");
btnGoToMarker.Image = ImageResources.images16x16.FirstOrDefault(x => x.Name == "16_icomoon_arrow-right");
}
partial void actionAddFilesToLibrary(NSObject sender)
{
IEnumerable<string> filePaths = null;
using(NSOpenPanel openPanel = new NSOpenPanel())
{
openPanel.CanChooseDirectories = false;
openPanel.CanChooseFiles = true;
openPanel.ReleasedWhenClosed = true;
openPanel.AllowsMultipleSelection = true;
openPanel.AllowedFileTypes = new string[]{ "FLAC", "MP3", "OGG", "WAV", "MPC", "WV" };
openPanel.Title = "Please select audio files to add to the library";
openPanel.Prompt = "Add files to library";
openPanel.RunModal();
filePaths = openPanel.Urls.Select(x => x.Path);
}
if(filePaths != null && filePaths.Count() > 0)
OnAddFilesToLibrary(filePaths.ToList());
}
partial void actionAddFolderLibrary(NSObject sender)
{
string folderPath = string.Empty;
using(NSOpenPanel openPanel = new NSOpenPanel())
{
openPanel.CanChooseDirectories = true;
openPanel.CanChooseFiles = false;
openPanel.ReleasedWhenClosed = true;
openPanel.AllowsMultipleSelection = false;
openPanel.Title = "Please select a folder to add to the library";
openPanel.Prompt = "Add folder to library";
openPanel.RunModal();
folderPath = openPanel.Url.Path;
}
if(!String.IsNullOrEmpty(folderPath))
OnAddFolderToLibrary(folderPath);
}
partial void actionOpenAudioFiles(NSObject sender)
{
IEnumerable<string> filePaths = null;
using(NSOpenPanel openPanel = new NSOpenPanel())
{
openPanel.CanChooseDirectories = false;
openPanel.CanChooseFiles = true;
openPanel.ReleasedWhenClosed = true;
openPanel.AllowsMultipleSelection = true;
openPanel.AllowedFileTypes = new string[]{ "FLAC", "MP3", "OGG", "WAV", "MPC", "WV" };
openPanel.Title = "Please select audio files to play";
openPanel.Prompt = "Add to playlist";
openPanel.RunModal();
filePaths = openPanel.Urls.Select(x => x.Path);
}
if(filePaths != null && filePaths.Count() > 0)
OnPlayerPlayFiles(filePaths);
}
partial void actionUpdateLibrary(NSObject sender)
{
OnUpdateLibrary();
}
partial void actionSoundFormatChanged(NSObject sender)
{
AudioFileFormat format;
Enum.TryParse<AudioFileFormat>(cboSoundFormat.TitleOfSelectedItem, out format);
OnAudioFileFormatFilterChanged(format);
}
partial void actionPlay(NSObject sender)
{
OnPlayerPause();
}
partial void actionPrevious(NSObject sender)
{
OnPlayerPrevious();
}
partial void actionNext(NSObject sender)
{
OnPlayerNext();
}
partial void actionRepeatType(NSObject sender)
{
}
partial void actionShuffle(NSObject sender)
{
}
partial void actionOpenMainWindow(NSObject sender)
{
this.Window.MakeKeyAndOrderFront(this);
}
partial void actionOpenPlaylistWindow(NSObject sender)
{
OnOpenPlaylistWindow();
}
partial void actionOpenEffectsWindow(NSObject sender)
{
OnOpenEffectsWindow();
}
partial void actionOpenPreferencesWindow(NSObject sender)
{
OnOpenPreferencesWindow();
}
partial void actionOpenSyncWindow(NSObject sender)
{
OnOpenSyncWindow();
}
partial void actionAddSongToPlaylist(NSObject sender)
{
}
partial void actionEditSongMetadata(NSObject sender)
{
}
partial void actionPlaySelectedSong(NSObject sender)
{
}
partial void actionChangeTimeShifting(NSObject sender)
{
OnPlayerSetTimeShifting(sliderTimeShifting.FloatValue);
}
partial void actionChangeSongPosition(NSObject sender)
{
}
partial void actionChangeVolume(NSObject sender)
{
OnPlayerSetVolume(sliderVolume.FloatValue);
}
partial void actionPlayLoop(NSObject sender)
{
}
partial void actionStopLoop(NSObject sender)
{
}
partial void actionAddLoop(NSObject sender)
{
}
partial void actionEditLoop(NSObject sender)
{
}
partial void actionRemoveLoop(NSObject sender)
{
}
partial void actionGoToMarker(NSObject sender)
{
if(tableMarkers.SelectedRow == -1)
return;
OnSelectMarker(_markers[tableMarkers.SelectedRow]);
}
partial void actionAddMarker(NSObject sender)
{
OnAddMarker(MarkerTemplateNameType.Verse);
}
partial void actionEditMarker(NSObject sender)
{
}
partial void actionRemoveMarker(NSObject sender)
{
}
partial void actionContextualMenuPlay(NSObject sender)
{
}
[Export ("numberOfRowsInTableView:")]
public int GetRowCount(NSTableView tableView)
{
if(tableView.Identifier == "tableMarkers")
return _markers.Count;
return 0;
}
[Export ("tableView:dataCellForTableColumn:row:")]
public NSObject GetObjectValue(NSTableView tableView, NSTableColumn tableColumn, int row)
{
return new NSString();
}
[Export ("tableView:viewForTableColumn:row:")]
public NSView GetViewForItem(NSTableView tableView, NSTableColumn tableColumn, int row)
{
NSTableCellView view;
view = (NSTableCellView)tableView.MakeView(tableColumn.Identifier.ToString().Replace("column", "cell"), this);
view.TextField.Font = NSFont.FromFontName("Junction", 11);
if (tableView.Identifier == "tableMarkers")
{
if (tableColumn.Identifier.ToString() == "columnMarkerName")
view.TextField.StringValue = _markers[row].Name;
else if (tableColumn.Identifier.ToString() == "columnMarkerPosition")
view.TextField.StringValue = _markers[row].Position;
else
view.TextField.StringValue = string.Empty;
}
return view;
}
[Export ("outlineViewItemDidExpand")]
public void ItemDidExpand(NSNotification notification)
{
// Check for dummy nodes
var item = (LibraryBrowserItem)notification.UserInfo["NSObject"];
if (item.SubItems.Count > 0 && item.SubItems[0].Entity.Type == LibraryBrowserEntityType.Dummy)
{
IEnumerable<LibraryBrowserEntity> entities = OnTreeNodeExpandable(item.Entity);
//Console.WriteLine("MainWindowController - ItemDidExpand - dummy node - entities.Count: {0}", entities.Count());
// Clear subitems (dummy node) and fill with actual nodes
item.SubItems.Clear();
foreach (LibraryBrowserEntity entity in entities)
item.SubItems.Add(new LibraryBrowserItem(entity));
outlineLibraryBrowser.ReloadData();
}
}
private void HandleMarkersDoubleClick(object sender, EventArgs e)
{
if (tableMarkers.SelectedRow == -1)
return;
OnSelectMarker(_markers[tableMarkers.SelectedRow]);
}
protected void HandleLibraryBrowserDoubleClick(object sender, EventArgs e)
{
if(outlineLibraryBrowser.SelectedRow == -1)
return;
LibraryBrowserItem item = (LibraryBrowserItem)outlineLibraryBrowser.ItemAtRow(outlineLibraryBrowser.SelectedRow);
if(OnTreeNodeDoubleClicked != null)
OnTreeNodeDoubleClicked.Invoke(item.Entity);
}
protected void HandleSongBrowserDoubleClick(object sender, EventArgs e)
{
if (tableSongBrowser.SelectedRow == -1)
return;
AudioFile audioFile = _songBrowserSource.Items[tableSongBrowser.SelectedRow].AudioFile;
if(OnTableRowDoubleClicked != null)
OnTableRowDoubleClicked.Invoke(audioFile);
}
public void RefreshAll()
{
OnAudioFileFormatFilterChanged(AudioFileFormat.All);
}
#region IPlayerView implementation
public System.Action OnPlayerPlay { get; set; }
public System.Action<IEnumerable<string>> OnPlayerPlayFiles { get; set; }
public System.Action OnPlayerPause { get; set; }
public System.Action OnPlayerStop { get; set; }
public System.Action OnPlayerPrevious { get; set; }
public System.Action OnPlayerNext { get; set; }
public System.Action<float> OnPlayerSetPitchShifting { get; set; }
public System.Action<float> OnPlayerSetTimeShifting { get; set; }
public System.Action<float> OnPlayerSetVolume { get; set; }
public System.Action<float> OnPlayerSetPosition { get; set; }
public Func<float, PlayerPositionEntity> OnPlayerRequestPosition { get; set; }
public void RefreshPlayerStatus(PlayerStatusType status)
{
InvokeOnMainThread(() => {
switch (status)
{
case PlayerStatusType.Initialized:
goto case PlayerStatusType.Paused;
case PlayerStatusType.Stopped:
goto case PlayerStatusType.Paused;
case PlayerStatusType.Paused:
toolbarMain.Items.FirstOrDefault(x => x.Identifier == "toolbarPlay").Image = ImageResources.images32x32.FirstOrDefault(x => x.Name == "32_icomoon_play");
toolbarMain.Items.FirstOrDefault(x => x.Identifier == "toolbarPlay").Label = "Play";
break;
case PlayerStatusType.Playing:
toolbarMain.Items.FirstOrDefault(x => x.Identifier == "toolbarPlay").Image = ImageResources.images32x32.FirstOrDefault(x => x.Name == "32_icomoon_pause");
toolbarMain.Items.FirstOrDefault(x => x.Identifier == "toolbarPlay").Label = "Pause";
break;
}
});
}
public void RefreshPlayerPosition(PlayerPositionEntity entity)
{
// When setting .StringValue, use a autorelease pool to keep the warnings away
// http://mono.1490590.n4.nabble.com/Memory-Leak-td3206211.html
using (NSAutoreleasePool pool = new NSAutoreleasePool())
{
// TODO: Bug CPU hit when updating label...
lblPosition.StringValue = entity.Position;
sliderPosition.SetPosition(entity.PositionPercentage * 100);
};
}
public void RefreshSongInformation(AudioFile audioFile, long lengthBytes, int playlistIndex, int playlistCount)
{
InvokeOnMainThread(() => {
lblArtistName.StringValue = audioFile.ArtistName;
lblAlbumTitle.StringValue = audioFile.AlbumTitle;
lblSongTitle.StringValue = audioFile.Title;
lblSongPath.StringValue = audioFile.FilePath;
//lblPosition.StringValue = audioFile.Position;
lblLength.StringValue = audioFile.Length;
lblFileType.StringValue = audioFile.FileType.ToString();
lblBitrate.StringValue = audioFile.Bitrate.ToString() + " kbit/s";
lblBitsPerSample.StringValue = audioFile.BitsPerSample.ToString() + " bits";
lblSampleRate.StringValue = audioFile.SampleRate.ToString() + " Hz";
// Set album cover
if (!String.IsNullOrEmpty(audioFile.FilePath))
{
NSImage image = AlbumCoverHelper.GetAlbumCover(audioFile.FilePath);
if (image != null)
imageAlbumCover.Image = image;
else
imageAlbumCover.Image = new NSImage();
}
else
{
imageAlbumCover.Image = new NSImage();
}
if(_songBrowserSource != null)
_songBrowserSource.RefreshIsPlaying(tableSongBrowser, audioFile.FilePath);
});
}
public void RefreshMarkers(IEnumerable<Marker> markers)
{
}
public void RefreshLoops(IEnumerable<Loop> loops)
{
}
public void RefreshPlayerVolume(PlayerVolumeEntity entity)
{
InvokeOnMainThread(() => {
lblVolume.StringValue = entity.VolumeString;
if(sliderVolume.FloatValue != entity.Volume)
sliderVolume.FloatValue = entity.Volume;
});
}
public void RefreshPlayerTimeShifting(PlayerTimeShiftingEntity entity)
{
InvokeOnMainThread(() => {
// lblTimeShifting.StingValue = entity.TimeShiftingString;
// if(sliderTimeShifting.FloatValue != entity.TimeShifting)
// sliderTimeShifting.FloatValue = entity.TimeShifting;
});
}
public void PlayerError(Exception ex)
{
InvokeOnMainThread(delegate {
CocoaHelper.ShowAlert("Error", string.Format("An error occured in the Player component: {0}", ex), NSAlertStyle.Critical);
});
}
#endregion
#region ISongBrowserView implementation
public System.Action<AudioFile> OnTableRowDoubleClicked { get; set; }
public void RefreshSongBrowser(IEnumerable<AudioFile> audioFiles)
{
InvokeOnMainThread(() => {
_songBrowserSource = new SongBrowserSource(audioFiles);
tableSongBrowser.Source = _songBrowserSource;
_albumCoverSource = new AlbumCoverSource(_albumCoverCacheService, audioFiles);
tableAlbumCovers.Source = _albumCoverSource;
});
}
#endregion
#region ILibraryBrowserView implementation
public System.Action<AudioFileFormat> OnAudioFileFormatFilterChanged { get; set; }
public System.Action<LibraryBrowserEntity> OnTreeNodeSelected { get; set; }
public System.Action<LibraryBrowserEntity, object> OnTreeNodeExpanded { get; set; }
public System.Action<LibraryBrowserEntity> OnTreeNodeDoubleClicked { get; set; }
public Func<LibraryBrowserEntity, IEnumerable<LibraryBrowserEntity>> OnTreeNodeExpandable { get; set; }
public void RefreshLibraryBrowser(IEnumerable<LibraryBrowserEntity> entities)
{
InvokeOnMainThread(() => {
_libraryBrowserDataSource = new LibraryBrowserDataSource(entities, (entity) => { return this.OnTreeNodeExpandable(entity); });
outlineLibraryBrowser.DataSource = _libraryBrowserDataSource;
});
}
public void RefreshLibraryBrowserNode(LibraryBrowserEntity entity, IEnumerable<LibraryBrowserEntity> entities, object userData)
{
// Not used in Cocoa.
}
#endregion
#region IMainView implementation
public System.Action OnOpenPreferencesWindow { get; set; }
public System.Action OnOpenEffectsWindow { get; set; }
public System.Action OnOpenPlaylistWindow { get; set; }
public System.Action OnOpenSyncWindow { get; set; }
public Action<List<string>> OnAddFilesToLibrary { get; set; }
public Action<string> OnAddFolderToLibrary { get; set; }
public Action OnUpdateLibrary { get; set; }
#endregion
#region IPitchShiftingView implementation
public Action<int> OnChangeKey { get; set; }
public Action<int> OnSetInterval { get; set; }
public Action OnResetInterval { get; set; }
public Action OnIncrementInterval { get; set; }
public Action OnDecrementInterval { get; set; }
public void PitchShiftingError(Exception ex)
{
InvokeOnMainThread(delegate {
CocoaHelper.ShowAlert("Error", string.Format("An error occured in the PitchShifting component: {0}", ex), NSAlertStyle.Critical);
});
}
public void RefreshKeys(List<Tuple<int, string>> keys)
{
}
public void RefreshPitchShifting(PlayerPitchShiftingEntity entity)
{
}
#endregion
#region ITimeShiftingView implementation
public Action<float> OnSetTimeShifting { get; set; }
public Action OnResetTimeShifting { get; set; }
public Action OnUseDetectedTempo { get; set; }
public Action OnIncrementTempo { get; set; }
public Action OnDecrementTempo { get; set; }
public void TimeShiftingError(Exception ex)
{
InvokeOnMainThread(delegate {
CocoaHelper.ShowAlert("Error", string.Format("An error occured in the TimeShifting component: {0}", ex), NSAlertStyle.Critical);
});
}
public void RefreshTimeShifting(PlayerTimeShiftingEntity entity)
{
}
#endregion
#region ILoopsView implementation
public Action OnAddLoop { get; set; }
public Action<Loop> OnEditLoop { get; set; }
public void LoopError(Exception ex)
{
InvokeOnMainThread(delegate {
CocoaHelper.ShowAlert("Error", string.Format("An error occured in the Loops component: {0}", ex), NSAlertStyle.Critical);
});
}
public void RefreshLoops(List<Loop> loops)
{
}
#endregion
#region IMarkersView implementation
public Action<MarkerTemplateNameType> OnAddMarker { get; set; }
public Action<Marker> OnEditMarker { get; set; }
public Action<Marker> OnSelectMarker { get; set; }
public void MarkerError(Exception ex)
{
InvokeOnMainThread(delegate {
CocoaHelper.ShowAlert("Error", string.Format("An error occured in the Markers component: {0}", ex), NSAlertStyle.Critical);
});
}
public void RefreshMarkers(List<Marker> markers)
{
InvokeOnMainThread(delegate {
_markers = markers.ToList();
tableMarkers.ReloadData();
});
}
#endregion
}
}