Esempio n. 1
0
        public void NormalizeSong()
        {
            _notesOfBar  = new Dictionary <int, List <Note> >();
            Versions     = new List <SongVersion>();
            _instruments = new List <GeneralMidi2Program>();

            Versions.Add(new SongVersion()
            {
                Notes         = MidiProcessing.GetNotesOfSong(OriginalMidiBase64Encoded),
                VersionNumber = 0
            });

            Bars = MidiProcessing.GetBarsOfSong(OriginalMidiBase64Encoded);

            foreach (var bar in Bars)
            {
                bar.HasTriplets = MidiProcessing.BarHasTriplets(this, bar);
            }
            Versions[0].Notes = MidiProcessing.QuantizeNotes(this, 0).ToList();

            TempoChanges = MidiProcessing.GetTempoChanges(this);
            ProcessedMidiBase64Encoded = MidiProcessing.GetMidiFromNotes(this, 0);
        }
Esempio n. 2
0
        private async Task ProcesameLaSong(string songPath, Band band, Style style)
        {
            try
            {
                if (!songPath.ToLower().EndsWith(".mid"))
                {
                    return;
                }
                try
                {
                    var lelo = MidiFile.Read(songPath, null);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, $"Song {songPath} esta podrida");
                    return;
                }

                var originalMidiBase64encoded = FileSystemUtils.GetBase64encodedFile(songPath);
                originalMidiBase64encoded = MidiProcessing.NormalizeTicksPerQuarterNote(originalMidiBase64encoded);

                Song song = new Song()
                {
                    Name  = Path.GetFileName(songPath),
                    Band  = band,
                    Style = style,
                    OriginalMidiBase64Encoded = originalMidiBase64encoded,
                };
                song = MidiProcessing.ComputeSongStats(song);
                song.TimeSignature = await SongRepository.GetTimeSignature(song.TimeSignature);


                song.NormalizeSong();
                song = await SongRepository.AddSong(song);

                song.FindSongPatterns();

                foreach (var oc in song.Versions[0].Occurrences)
                {
                    var pattern = oc.Pattern;
                    var patito  = await SongRepository.GetPatternByStringAndTypeAsync(pattern.AsString, pattern.PatternTypeId);

                    if (patito == null)
                    {
                        patito = SongRepository.AddPatternAsync(pattern);
                    }
                    oc.Pattern       = patito;
                    oc.PatternId     = patito.Id;
                    oc.SongVersionId = song.Versions[0].Id;
                }
                await SongRepository.UpdateSong(song);


                var outputPath = Path.Combine(@"C:\music\procesados", song.Name);
                var bytes      = Convert.FromBase64String(song.ProcessedMidiBase64Encoded);
                System.IO.File.WriteAllBytes(outputPath, bytes);
            }
            catch (Exception sorete)
            {
            }
        }