コード例 #1
0
        private bool AddMusic(string musicName, MusicFile musicFile, bool forceReplace)
        {
            var musicNameLower = musicName.ToLowerInvariant();

            if (MusicFiles.ContainsKey(musicNameLower))
            {
                if (forceReplace && MusicFiles[musicNameLower].IsStandard)
                {
                    MusicFiles.Remove(musicNameLower);
                }
                else
                {
                    return(true);
                }
            }
            MusicFiles.Add(musicNameLower, new MusicClip(musicFile));

            // TODO: Loading every music increases uned memory size duh
            //if (!musicFile.ForceLoad())
            //{
            //    Logger.Log(Logger.LogTypes.Warning, $"MusicTrack.cs: File at \"{musicFile.LocalPath}\" is not a valid music file!");
            //    return false;
            //}
            return(true);
        }
コード例 #2
0
 private void MusicFileServiceOnMusicFileLoaded(object sender, MusicFileLoadedEventArgs eventArgs)
 {
     Device.BeginInvokeOnMainThread(() =>
     {
         MusicFiles.Add(eventArgs.MusicFile);
     });
 }
コード例 #3
0
 private IEnumerable <string> GetOrchestras()
 {
     return(MusicFiles
            .Where(x => x.GetOrchestra() != null)
            .Select(x => MusicOptions.ReplaceAlias(x.GetOrchestra()))
            .Distinct(comparer)
            .OrderBy(x => x));
 }
コード例 #4
0
 private IEnumerable <string> GetConductors()
 {
     return(MusicFiles
            .Where(x => x.GetConductor() != null)
            .Select(x => MusicOptions.ReplaceAlias(x.GetConductor()))
            .Distinct(comparer)
            .OrderBy(x => x.GetLastName()));
 }
コード例 #5
0
ファイル: Extensions.cs プロジェクト: asimshah/Music
        public static IEnumerable <(Track track, long musicFileId)> GetTracks(this MusicDb db, IPlayable playable)
        {
            var list = new List <(Track track, long musicFileId)>();

            //await db.LoadRelatedEntities(playable);
            foreach (var track in playable.Tracks.OrderBy(t => t.Number))
            {
                //await db.LoadRelatedEntities(track);
                list.Add((track, track.MusicFiles.OrderByDescending(mf => mf.Rank()).First().Id));
            }
            return(list);
        }
コード例 #6
0
 public void ScanFileLocations(BackgroundWorker worker, DoWorkEventArgs e)
 {
     if (worker.CancellationPending)
     {
         e.Cancel = true;
     }
     else
     {
         try
         {
             int highestPercentageReached = 0;
             foreach (var file in FileLocations)
             {
                 int percentComplete = (int)((float)Array.IndexOf(FileLocations, file) / (float)Array.LastIndexOf(FileLocations, file) * 100);
                 if (percentComplete > highestPercentageReached)
                 {
                     highestPercentageReached = percentComplete;
                     worker.ReportProgress(percentComplete);
                 }
                 foreach (var ext in MusicExt)
                 {
                     string[] filePaths = Directory.GetFiles(file, ext, SearchOption.AllDirectories);
                     foreach (var files in filePaths)
                     {
                         MusicFiles.Add(new Music(files));
                     }
                 }
                 foreach (var ext in VideoExt)
                 {
                     string[] filePaths = Directory.GetFiles(file, ext, SearchOption.AllDirectories);
                     foreach (var files in filePaths)
                     {
                         VideoFiles.Add(new Video(files));
                     }
                 }
                 foreach (var ext in OtherExt)
                 {
                     string[] filePaths = Directory.GetFiles(file, ext, SearchOption.AllDirectories);
                     foreach (var files in filePaths)
                     {
                         MediaFiles.Add(new MediaFiles(files));
                     }
                 }
             }
         }
         catch (Exception exc)
         {
             throw new ArgumentException(exc.ToString());
         }
     }
 }
コード例 #7
0
ファイル: Program.cs プロジェクト: DanqingYANG/MscMngTest
        static void Main(string[] args)
        {
            Tools.FolderSelector folder = new Tools.FolderSelector();
            folder.subFolders(@"F:\music");
            List <string> b = new List <string>();

            b = folder.setFileType("jpg, png, , ,txt, mp3, cue, ape");
            folder.getFileNames(@"F:\music\Bach\Bach.-.[Goldberg.Variations(Walcha.EMI.Angle)].专辑.(Flac)", b);


            Tools.MusicFiles playlist = new MusicFiles();
            playlist.getFiles(@"F:\music\Mozart-Requiem-Bernstein (APE)");
            playlist.test();
        }
コード例 #8
0
        protected (CatalogueStatus status, IEnumerable <Track> tracks) CatalogueTracks(Artist artist, Work album)
        {
            Debug.Assert(MusicDb != null);
            var tracks = new List <Track>();
            var result = CatalogueStatus.Success;

            if (!generated || MusicOptions.AllowOutOfDateGeneratedFiles || album.LastModified < FirstFile.FileLastWriteTimeUtc)
            {
                var filesByPart = MusicFiles.GroupBy(x => x.PartNumber);
                int count       = 0;
                foreach (var group in filesByPart.OrderBy(x => x.Key))
                {
                    var files = group.Select(x => x).ToArray();
                    //foreach(var mf in files)
                    for (int i = 0; i < files.Count(); ++i)
                    {
                        var mf    = files[i];
                        var track = GetTrack(artist, album, mf, i, count);
                        tracks.Add(track);
                    }
                    count += files.Count();
                }
                //foreach (var mf in MusicFiles)
                //{
                //    var track = GetTrack(artist, album, mf);
                //    tracks.Add(track);
                //}
            }
            else
            {
                // generated files are older than the album record
                // and may be out of date
                var path = Path.Combine(FirstFile.DiskRoot, FirstFile.StylePath, FirstFile.OpusPath);
                log.Warning($"{MusicFiles.Count()} files in {path} are generated and possibly out-of-date - files not catalogued");
                result = CatalogueStatus.GeneratedFilesOutOfDate;
                if (album.Tracks.Count() == 0)
                {
                    artist.Works.Remove(album);
                    if (artist.Works.Count() == 0)
                    {
                        MusicDb.Artists.Remove(artist);
                    }
                }
            }
            return(result, tracks);
        }
コード例 #9
0
        private Performance GetPerformance(Composition composition, string orchestras, string conductors, string performers)
        {
            Debug.Assert(MusicDb != null);
            var performance = composition.Performances.SingleOrDefault(p =>
                                                                       p.Orchestras.IsEqualIgnoreAccentsAndCase(orchestras) &&
                                                                       p.Conductors.IsEqualIgnoreAccentsAndCase(conductors) &&
                                                                       p.Performers.IsEqualIgnoreAccentsAndCase(performers));

            if (performance != null)
            {
                // find a unique name for this performance
                var index = 1;
                var found = false;
                while (!found)
                {
                    var name = $"{performers} ({++index})";
                    performance = composition.Performances.SingleOrDefault(p => p.Performers.IsEqualIgnoreAccentsAndCase(name));
                    found       = performance == null;
                }
            }

            performance = new Performance
            {
                Composition          = composition,
                Orchestras           = orchestras,
                Conductors           = conductors,
                Performers           = performers,
                AlphamericPerformers = performers.ToAlphaNumerics(),
                Year = FirstFile.GetYear() ?? 0
            };
            var movementNumber = 0;

            foreach (var track in MusicFiles.Select(mf => mf.Track).OrderBy(x => x.Number))
            {
                if (track == null || track.Performance != null)
                {
                    Debugger.Break();
                }
                track.MovementNumber = ++movementNumber;
                performance.Movements.Add(track);
            }
            Debug.Assert(performance.Movements.Count > 0);
            composition.Performances.Add(performance);
            return(performance);
        }
コード例 #10
0
        public async void ImportFromMidiAsync()
        {
            var filePicker = new FileOpenPicker {
                ViewMode = PickerViewMode.List
            };


            filePicker.FileTypeFilter.Add(".mid");
            filePicker.FileTypeFilter.Add(".midi");
            filePicker.FileTypeFilter.Add(".smf");

            filePicker.CommitButtonText = "Import";

            StorageFile file = await filePicker.PickSingleFileAsync();

            if (file == null)
            {
                return;
            }

            if (file.ContentType != "audio/mid" &&
                file.ContentType != "audio/midi")
            {
                await
                new MessageDialog("Please select a valid standard midi file.", "Selected file is not a midi file!").ShowAsync();
                return;
            }


            IStorageItem rootDir = await ApplicationData.Current.RoamingFolder.TryGetItemAsync("Music");

            if (rootDir == null)
            {
                await new MessageDialog("Please restart this app!", "Music Folder is not found!").ShowAsync();
                return;
            }
            if ((await ImportAsync(file)) is StorageFile f)
            {
                MusicFiles.Add(f);
            }
        }
コード例 #11
0
        public MusicClip GetMusic(string musicName, bool logErrors)
        {
            var lowerMusicName = musicName.ToLowerInvariant();

            if (MusicFiles.ContainsKey(lowerMusicName))
            {
                return(MusicFiles[lowerMusicName]);
            }

            if (TryAddGameModeMusic(lowerMusicName))
            {
                return(MusicFiles[lowerMusicName]);
            }

            if (logErrors && lowerMusicName != "nomusic")
            {
                Logger.Log(Logger.LogTypes.Warning, $"MusicManager.cs: Cannot find music file \"{musicName}\". Return nothing.");
            }

            return(null);
        }
コード例 #12
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (this.folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {

                string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.mp3" , SearchOption.AllDirectories);
                if (files.Length > 0)
                {
                    TagLib.File tfile;
                    this.progressBar1.Value = 0;
                    this.progressBar1.Maximum = files.Length;
                    this.progressBar1.Minimum = 0;
                    this.label1.Text = "0";
                    int counter = 0;

                    msic = new MusicFiles[files.Length];
                    foreach (string filename in files)
                    {
                        msic[counter] = new MusicFiles();
                        msic[counter].id = counter;
                        msic[counter].filename = filename;
                        msic[counter].safefilename = filename;
                        msic[counter].m_thread = new Thread(new ParameterizedThreadStart(doLoadMe));
                        counter += 1;
                    }

                    if (msic.Length > 1)
                    {
                        msic[0].m_thread.Start(msic[0]);
                        //msic[1].m_thread.Start(msic[1]);
                    }

                }
            }
        }
コード例 #13
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            TagLib.File tfile;
            int counter = 0;
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.progressBar1.Value = 0;
                this.progressBar1.Maximum = openFileDialog1.FileNames.Length;
                this.progressBar1.Minimum = 0;
                this.label1.Text = "0";

                msic = new MusicFiles[openFileDialog1.FileNames.Length];
                foreach (string filename in openFileDialog1.FileNames)
                {
                    msic[counter] = new MusicFiles();
                    msic[counter].id = counter;
                    msic[counter].filename = openFileDialog1.FileNames[counter];
                    msic[counter].safefilename = openFileDialog1.SafeFileNames[counter];
                    msic[counter].m_thread = new Thread(new ParameterizedThreadStart(doLoadMe));
                    counter += 1;
                }

                if (msic.Length > 1)
                {
                    msic[0].m_thread.Start(msic[0]);
                    //msic[1].m_thread.Start(msic[1]);
                }
                else
                {
                    msic[0].m_thread.Start(msic[0]);
                }
            }
        }
コード例 #14
0
 public Assets()
 {
     Sounds = new SoundFiles(this);
     Music  = new MusicFiles(this);
 }
コード例 #15
0
	public static float GetTrackLength(MusicFiles n) {
		var mcb = GameObject.FindGameObjectWithTag(Tags.MUSICCONTROLLER).GetComponent<MusicControllerBehavior>();
		return mcb.Music[(int)n].length;
	}
コード例 #16
0
 public bool Contains(string musicName) => MusicFiles.ContainsKey(Exceptions(musicName));
コード例 #17
0
 public void ReloadMusic()
 {
     MusicFiles.Clear();
     LoadMusic();
 }
コード例 #18
0
    public static float GetTrackLength(MusicFiles n)
    {
        var mcb = GameObject.FindGameObjectWithTag(Tags.MUSICCONTROLLER).GetComponent <MusicControllerBehavior>();

        return(mcb.Music[(int)n].length);
    }
コード例 #19
0
 public override string ToString()
 {
     return($"{this.GetType().Name}::{ComposerName}::{CompositionName}::{MusicFiles.Count()} files");
 }
コード例 #20
0
        protected override async Task LoadMusicTags()
        {
            var json = await ReadMusicTagJson();

            if (json != null)
            {
                var teo = json.ToInstance <WesternClassicalAlbumTEO>();
                performanceTEO = teo.PerformanceList.Single(x =>
                                                            x.MovementFilenames.All(f => MusicFiles.Select(mf => mf.File).SingleOrDefault(x => x.EndsWith(f, System.Globalization.CompareOptions.IgnoreCase)) != null)
                                                            );
                ComposerName    = performanceTEO.ComposerTag.GetValue <string>();
                CompositionName = performanceTEO.CompositionTag.GetValue <string>();
                orchestras      = performanceTEO.OrchestraTag.GetValues <string>();
                conductors      = performanceTEO.ConductorTag.GetValues <string>();
                otherPerformers = performanceTEO.PerformerTag.GetValues <string>();
            }
        }
コード例 #21
0
		public Assets()
		{
			Sounds = new SoundFiles(this);
			Music = new MusicFiles(this);
		}
コード例 #22
0
        public MainPageViewModel()
        {
            _musicFiles = new ObservableCollection <StorageFile>();
            CurrentFile = new GroorineFileViewModel(null);
            //_player = new Player();
            InitializeAsync();
            DeleteCommand = new DelegateCommand(async(o) =>
            {
                if (!(o is StorageFile))
                {
                    return;
                }
                var sf = o as StorageFile;
                MusicFiles.Remove(sf);
                await sf.DeleteAsync();
            });

            ExportCommand = new DelegateCommand(async(o) =>
            {
                if (!(o is StorageFile))
                {
                    return;
                }
                var sf  = o as StorageFile;
                var fsp = new FileSavePicker();
                fsp.FileTypeChoices.Add("Wave Audio", new List <string> {
                    ".wav"
                });
                fsp.FileTypeChoices.Add("Windows Media Audio", new List <string> {
                    ".wma"
                });
                fsp.FileTypeChoices.Add("MPEG 3 Audio", new List <string> {
                    ".mp3"
                });
                fsp.FileTypeChoices.Add("MPEG 4 Audio", new List <string> {
                    ".m4a"
                });
                fsp.SuggestedFileName = sf.DisplayName;
                fsp.CommitButtonText  = "Bounce";

                StorageFile file = await fsp.PickSaveFileAsync();
                if (file == null)
                {
                    return;
                }

                MediaEncodingProfile mediaEncodingProfile;
                switch (file.FileType.ToString().ToLowerInvariant())
                {
                case ".wma":
                    mediaEncodingProfile = MediaEncodingProfile.CreateWma(AudioEncodingQuality.High);
                    break;

                case ".mp3":
                    mediaEncodingProfile = MediaEncodingProfile.CreateMp3(AudioEncodingQuality.High);
                    break;

                case ".wav":
                    mediaEncodingProfile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.High);
                    break;

                case ".m4a":
                    mediaEncodingProfile = MediaEncodingProfile.CreateM4a(AudioEncodingQuality.High);
                    break;

                default:
                    throw new ArgumentException();
                }

                CreateAudioFileOutputNodeResult result = await _graph.CreateFileOutputNodeAsync(file, mediaEncodingProfile);

                if (result.Status != AudioFileNodeCreationStatus.Success)
                {
                    // FileOutputNode creation failed
                    await new MessageDialog("We couldn't create FileOutputNode, so we failed to bounce.").ShowAsync();
                    return;
                }

                AudioFileOutputNode node = result.FileOutputNode;

                _graph.Stop();

                _frameInputNode.AddOutgoingConnection(node);
                Stop();
                _player.Load(SmfParser.Parse(await sf.OpenStreamForReadAsync()));

                Play();

                _graph.Start();
                var a = new BouncingDialog();

#pragma warning disable CS4014 // この呼び出しを待たないため、現在のメソッドの実行は、呼び出しが完了する前に続行します
                a.ShowAsync();
#pragma warning restore CS4014 // この呼び出しを待たないため、現在のメソッドの実行は、呼び出しが完了する前に続行します



                while (_player.IsPlaying)
                {
                    await Task.Delay(1);
                }
                _graph.Stop();

                await node.FinalizeAsync();

                _graph.Start();

                a.Hide();
                await new MessageDialog("Bouncing has successfully finished!").ShowAsync();
            });
        }
コード例 #23
0
 public override string ToString()
 {
     return($"{this.GetType().Name}::{ArtistName}::{AlbumName}::{MusicFiles.Count()} files");
 }