Ejemplo n.º 1
0
    private static void ReadSync(IList <MidiEvent> track, Song song)
    {
        foreach (var me in track)
        {
            var ts = me as TimeSignatureEvent;
            if (ts != null)
            {
                var tick = me.AbsoluteTime;

                song.Add(new TimeSignature((uint)tick, (uint)ts.Numerator, (uint)(Mathf.Pow(2, ts.Denominator))), false);
                continue;
            }
            var tempo = me as TempoEvent;
            if (tempo != null)
            {
                var tick = me.AbsoluteTime;
                song.Add(new BPM((uint)tick, (uint)(tempo.Tempo * 1000)), false);
                continue;
            }

            // Read the song name
            var text = me as TextEvent;
            if (text != null)
            {
                song.name = text.Text;
            }
        }

        song.UpdateCache();
    }
Ejemplo n.º 2
0
    private static void ReadSongGlobalEvents(IList <MidiEvent> track, Song song)
    {
        for (int i = 1; i < track.Count; ++i)
        {
            var text = track[i] as TextEvent;

            if (text != null)
            {
                if (text.Text.Contains("[section "))
                {
                    song.Add(new Section(text.Text.Substring(9, text.Text.Length - 10), (uint)text.AbsoluteTime), false);
                }
                else if (text.Text.Contains("[prc_"))       // No idea what this actually is
                {
                    song.Add(new Section(text.Text.Substring(5, text.Text.Length - 6), (uint)text.AbsoluteTime), false);
                }
                else
                {
                    song.Add(new Event(text.Text.Trim(new char[] { '[', ']' }), (uint)text.AbsoluteTime), false);
                }
            }
        }

        song.UpdateCache();
    }
Ejemplo n.º 3
0
    public static void ApplyAction(SongObject songObject)
    {
        ChartEditor editor = ChartEditor.Instance;
        Song        song   = editor.currentSong;
        Chart       chart  = editor.currentChart;

        songObject = songObject.Clone();    // Add a new version of the object

        switch (songObject.classID)
        {
        case (int)SongObject.ID.Note:
            Note note = songObject as Note;
            chart.Add(note);

            foreach (Note chordNote in note.chord)
            {
                if (chordNote.controller)
                {
                    chordNote.controller.SetDirty();
                }
            }

            Note next = note.nextSeperateNote;
            if (next != null)
            {
                foreach (Note chordNote in next.chord)
                {
                    if (chordNote.controller)
                    {
                        chordNote.controller.SetDirty();
                    }
                }
            }
            break;

        case (int)SongObject.ID.Starpower:
            Starpower sp = songObject as Starpower;
            chart.Add(sp, false);
            SongEditAdd.SetNotesDirty(sp, editor.currentChart.chartObjects);
            break;

        case (int)SongObject.ID.ChartEvent:
            chart.Add(songObject as ChartObject, false);
            break;

        case (int)SongObject.ID.Section:
        case (int)SongObject.ID.Event:
            song.Add(songObject as Event, false);
            break;

        case (int)SongObject.ID.BPM:
            song.Add(songObject as SyncTrack, false);
            ChartEditor.Instance.songObjectPoolManager.SetAllPoolsDirty();
            break;

        case (int)SongObject.ID.TimeSignature:
            song.Add(songObject as SyncTrack, false);
            break;
        }
    }
        void AnalyzeInterClusterDistance()
        {
            List <Song> centroids     = Model.Centroids;
            int         clustersCount = centroids.Count;

            if (clustersCount == 0)
            {
                throw new ArgumentException("No clusters.");
            }

            const string id = "centroids_center";
            Song         centroidsCenter = centroids[0].CloneCleared(id);

            for (int i = 1; i < clustersCount; i++)
            {
                Song centroid = centroids[i];
                centroidsCenter.Add(centroid);
            }

            centroidsCenter.Divide(clustersCount);

            IDistanceFunc distanceFunc = Model.DistanceFunc;

            InterClusterMeanDistance = 0.0;

            foreach (Song centroid in centroids)
            {
                InterClusterMeanDistance += distanceFunc.GetDistance(centroid, centroidsCenter);
            }

            InterClusterMeanDistance /= clustersCount;
        }
Ejemplo n.º 5
0
        public Song Parse()
        {
            var song = new Song();

            int? tempo = _score.Parts.First().Measures.First().Directions.Where(x => x.Placement == DirectionPlacement.Above).First().Tempo;

            if (tempo == null)
            {
                song.Tempo = 100;
            }
            else
            {
                song.Tempo = (int)tempo;
            }

            double currentNoteTime = 0;
            double currentDevisions = 4;

            foreach (Part part in _score.Parts)
                foreach (Measure measure in part.Measures)
                {

                    MeasureAttributes attributes = measure.Attributes;
                    if (attributes != null)
                    {
                        if (attributes.Divisions != -1) currentDevisions = attributes.Divisions;
                    }

                    double lastNoteDuration = 0;

                    foreach (Note note in measure.Notes)
                    {
                        //If the current note is part of a chord, we need to revert to the previous NoteTime
                        if (note.IsChord) currentNoteTime -= lastNoteDuration / currentDevisions;

                        //After current note drawn, handle keeping track of noteTime in the piece
                        switch (note.NoteType)
                        {
                            case Note.NoteTypes.Note:
                                song.Add(ConvertXmlNoteToSongNote(currentNoteTime, note));
                                currentNoteTime += note.Duration / currentDevisions;
                                break;
                            case Note.NoteTypes.Backup:
                                currentNoteTime -= note.Duration / currentDevisions;
                                break;
                            case Note.NoteTypes.Forward:
                                currentNoteTime += note.Duration / currentDevisions;
                                break;
                            default:
                                currentNoteTime += note.Duration / currentDevisions;
                                break;
                        }
                        lastNoteDuration = note.Duration;
                    }
                }

            return song;
        }
Ejemplo n.º 6
0
        public override bool Insert(string json)
        {
            var data = JsonConvert.DeserializeObject <RootObject>(json);

            if (data == null || !data.Songlog.Any())
            {
                return(false);
            }

            if (data.pageSize < data.Songlog.Count)
            {
                var log = new ImportInfo();
                log.Messages.Add("data.pageSize < data.Songlog.Count: " + data.Id + " => " + data.pageSize + " < " + data.Songlog.Count);
                ImportLog.Add(log);
            }

            using (var db = new SrfPlayListContext(OptionsBuilder.Options))
            {
                foreach (var songLogData in data.Songlog)
                {
                    // check for already imported songlog
                    var songlog = db.Songlogs.Local.FirstOrDefault(s => s.id.Equals(songLogData.id));
                    if (songlog == default(Songlog))
                    {
                        songlog = db.Songlogs.FirstOrDefault(s => s.id.Equals(songLogData.id));
                    }
                    if (songlog != default(Songlog))
                    {
                        continue;
                    }

                    var artist = Artist.Add(db, songLogData);
                    var song   = Song.Add(db, songLogData, artist);

                    // checked for existing above
                    songlog = Songlog.Add(db, songLogData, song);

                    var log = new ImportInfo
                    {
                        Artist     = artist.name,
                        Song       = song.title,
                        PlayedDate = songlog.playedDate
                    };
                    ImportLog.Add(log);
                }

                db.SaveChanges();
            }

            return(true);
        }
Ejemplo n.º 7
0
    void AddRandomSections(Song song, float songLength)
    {
        uint      maxTickPosition  = song.TimeToTick(songLength, song.resolution);
        const int maxSections      = 100;
        int       numberOfSections = Random.Range(0, maxSections);

        for (int i = 0; i < numberOfSections; ++i)
        {
            string  sectionName  = GenerateRandomSectionName();
            uint    tickPosition = (uint)Random.Range(0, (int)maxTickPosition);
            Section section      = new Section(sectionName, tickPosition);
            song.Add(section);
        }
    }
Ejemplo n.º 8
0
    private static void ReadTextEventsIntoGlobalEventsAsLyrics(IList <MidiEvent> track, Song song)
    {
        for (int i = 1; i < track.Count; ++i)
        {
            var text = track[i] as TextEvent;

            if (text != null && text.Text.Length > 0 && text.Text[0] != '[')
            {
                string lyricEvent = MidIOHelper.LYRIC_EVENT_PREFIX + text.Text;
                song.Add(new Event(lyricEvent, (uint)text.AbsoluteTime), false);
            }
        }

        song.UpdateCache();
    }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            var httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri(ServerAddress);

            // Artists with JSON
            var artist = new ArtistApiModel()
            {
                Name = "Pesho123", Country = "Bulgaria", DateOfBirth = DateTime.Now
            };

            Console.WriteLine("Adding following artist " + artist);
            Console.WriteLine("-----------------------------------");
            Artist.Add(httpClient, artist);
            Console.ReadLine();
            Console.WriteLine("Listing all artists");
            Console.WriteLine("-----------------------------------");
            Artist.Print(httpClient);
            Console.ReadLine();
            var updatedArtist = new ArtistApiModel()
            {
                Name = "PeshoUpdated", Country = "Zimbabve", DateOfBirth = DateTime.Now
            };

            Console.WriteLine("Update artist with ID 1 to " + updatedArtist);
            Console.WriteLine("-----------------------------------");
            Artist.Update(httpClient, 1, artist);
            Console.ReadLine();
            Console.WriteLine("Delete artist with ID 1");
            Console.WriteLine("-----------------------------------");
            Artist.Delete(httpClient, 1);
            Console.ReadLine();

            // Songs with XML
            var song = new SongApiModel()
            {
                Title = "Nothing else matters", Genre = "Blues", Year = 1995, ArtistId = 1
            };

            Song.Add(httpClient, song);
            Console.ReadLine();

            Console.WriteLine("-----------------------------------");
            Song.Print(httpClient);
            Console.ReadLine();
        }
Ejemplo n.º 10
0
        public static void AddSongNoteToSong(double noteTime, Song song, Note xmlNote, double duration)
        {
            var songNote = new SongNote();
            songNote.NoteTime = noteTime;
            songNote.PitchId = GetPitchIdFromNote(xmlNote);
            songNote.Velocity = 100;

            songNote.Duration = duration;

            SongNoteEventCollections noteEventCollections;

            if (!song.TryGetValue(noteTime, out noteEventCollections))
            {
                noteEventCollections = new SongNoteEventCollections();
                song.Add(noteTime, noteEventCollections);
            };

            noteEventCollections.KeyPresses.Add(songNote);
        }
Ejemplo n.º 11
0
    public static void ApplyPostValidatedAction(SongObject songObject)
    {
        switch (songObject.classID)
        {
        case ((int)SongObject.ID.Note):
        {
            Note        note   = songObject as Note;
            ChartEditor editor = ChartEditor.Instance;
            Chart       chart  = editor.currentChart;
            chart.Add(note);

            foreach (Note chordNote in note.chord)
            {
                if (chordNote.controller)
                {
                    chordNote.controller.SetDirty();
                }
            }

            Note next = note.nextSeperateNote;
            if (next != null)
            {
                foreach (Note chordNote in next.chord)
                {
                    if (chordNote.controller)
                    {
                        chordNote.controller.SetDirty();
                    }
                }
            }
        }
        break;

        case ((int)SongObject.ID.Starpower):
        case ((int)SongObject.ID.ChartEvent):
        {
            ChartEditor editor = ChartEditor.Instance;
            Chart       chart  = editor.currentChart;
            chart.Add(songObject as ChartObject);
        }
        break;

        case ((int)SongObject.ID.BPM):
        case ((int)SongObject.ID.TimeSignature):
        {
            ChartEditor editor = ChartEditor.Instance;
            Song        song   = editor.currentSong;
            song.Add(songObject as SyncTrack);
        }
        break;

        case ((int)SongObject.ID.Section):
        case ((int)SongObject.ID.Event):
        {
            ChartEditor editor = ChartEditor.Instance;
            Song        song   = editor.currentSong;
            song.Add(songObject as Event);
        }
        break;

        default:
            Debug.LogError("Unhandled songobject!");
            break;
        }
    }
    static void SubmitDataGlobals(Song song, List <string> stringData)
    {
        const int TEXT_POS_TICK       = 0;
        const int TEXT_POS_EVENT_TYPE = 2;
        const int TEXT_POS_DATA_1     = 3;

#if TIMING_DEBUG
        float time = Time.realtimeSinceStartup;
#endif

        List <Anchor> anchorData = new List <Anchor>();

        foreach (string line in stringData)
        {
            string[] stringSplit = line.Split(' ');
            uint     tick;
            string   eventType;
            if (stringSplit.Length > TEXT_POS_DATA_1 && uint.TryParse(stringSplit[TEXT_POS_TICK], out tick))
            {
                eventType = stringSplit[TEXT_POS_EVENT_TYPE];
                eventType = eventType.ToLower();
            }
            else
            {
                continue;
            }

            switch (eventType)
            {
            case ("ts"):
                uint numerator;
                uint denominator = 2;

                if (!uint.TryParse(stringSplit[TEXT_POS_DATA_1], out numerator))
                {
                    continue;
                }

                if (stringSplit.Length > TEXT_POS_DATA_1 + 1 && !uint.TryParse(stringSplit[TEXT_POS_DATA_1 + 1], out denominator))
                {
                    continue;
                }

                song.Add(new TimeSignature(tick, numerator, (uint)(Mathf.Pow(2, denominator))), false);
                break;

            case ("b"):
                uint value;
                if (!uint.TryParse(stringSplit[TEXT_POS_DATA_1], out value))
                {
                    continue;
                }

                song.Add(new BPM(tick, value), false);
                break;

            case ("e"):
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                int  startIndex = TEXT_POS_DATA_1;
                bool isSection  = false;

                if (stringSplit.Length > TEXT_POS_DATA_1 + 1 && stringSplit[TEXT_POS_DATA_1] == "\"section")
                {
                    startIndex = TEXT_POS_DATA_1 + 1;
                    isSection  = true;
                }

                for (int i = startIndex; i < stringSplit.Length; ++i)
                {
                    sb.Append(stringSplit[i].Trim('"'));
                    if (i < stringSplit.Length - 1)
                    {
                        sb.Append(" ");
                    }
                }

                if (isSection)
                {
                    song.Add(new Section(sb.ToString(), tick), false);
                }
                else
                {
                    song.Add(new Event(sb.ToString(), tick), false);
                }

                break;

            case ("a"):
                ulong anchorValue;
                if (ulong.TryParse(stringSplit[TEXT_POS_DATA_1], out anchorValue))
                {
                    Anchor a;
                    a.tick       = tick;
                    a.anchorTime = (float)(anchorValue / 1000000.0d);
                    anchorData.Add(a);
                }
                break;

            default:
                break;
            }
        }

        BPM[] bpms = song.syncTrack.OfType <BPM>().ToArray();        // BPMs are currently uncached
        foreach (Anchor anchor in anchorData)
        {
            int arrayPos = SongObjectHelper.FindClosestPosition(anchor.tick, bpms);
            if (bpms[arrayPos].tick == anchor.tick)
            {
                bpms[arrayPos].anchor = anchor.anchorTime;
            }
            else
            {
                // Create a new anchored bpm
                uint value;
                if (bpms[arrayPos].tick > anchor.tick)
                {
                    value = bpms[arrayPos - 1].value;
                }
                else
                {
                    value = bpms[arrayPos].value;
                }

                BPM anchoredBPM = new BPM(anchor.tick, value);
                anchoredBPM.anchor = anchor.anchorTime;
            }
        }
#if TIMING_DEBUG
        Debug.Log("Synctrack load time: " + (Time.realtimeSinceStartup - time));
#endif
    }
Ejemplo n.º 13
0
        /// <summary>
        /// This method will process a given character and add a corrosponding note to the song
        /// </summary>
        public static void AddNoteFromChar(char note)
        {
            Delay delay = Delays.Find(x => x.Character == note);

            //Start multinote building if the input is a [
            if (note == '[')
            {
                if (buildingMultiNote)
                {
                    AddingNotesFailed?.Invoke();
                    throw new AutoplayerInvalidMultiNoteException("A multi note cannot be defined whithin a multinote definition!");
                }
                buildingMultiNote = true;
                multiNoteBuffer.Clear();
            }
            //Stop multinote building if the input is a ] and add a multinote
            else if (note == ']')
            {
                if (!buildingMultiNote)
                {
                    AddingNotesFailed?.Invoke();
                    throw new AutoplayerMultiNoteNotDefinedException("A multi note must have a start before the end!");
                }
                buildingMultiNote = false;
                Song.Add(new MultiNote(multiNoteBuffer.ToArray(), multiNoteIsHighNote));
                multiNoteBuffer.Clear();
            }
            //Start fast speed if the input is a {
            else if (note == '{')
            {
                //If it's part of a multinote we want to add it to the multinote buffer
                //Otherwise add it as a single note
                if (buildingMultiNote)
                {
                    AddingNotesFailed?.Invoke();
                    throw new AutoplayerInvalidMultiNoteException("A speed change note cannot be defined whithin a multinote definition!");
                }
                else
                {
                    Song.Add(new SpeedChangeNote(true));
                }
            }
            //Stop fast speed if the input is a }
            else if (note == '}')
            {
                if (buildingMultiNote)
                {
                    AddingNotesFailed?.Invoke();
                    throw new AutoplayerInvalidMultiNoteException("A speed change note cannot be defined whithin a multinote definition!");
                }
                else
                {
                    Song.Add(new SpeedChangeNote(false));
                }
            }
            //If the input is registered as a delay, add a delay note
            else if (delay != null)
            {
                if (buildingMultiNote)
                {
                    AddingNotesFailed?.Invoke();
                    throw new AutoplayerInvalidMultiNoteException("A delay note cannot be defined whithin a multinote definition!");
                }
                else
                {
                    Song.Add(new DelayNote(delay.Character, delay.Time));
                }
            }
            //If we reach a newline, we just ignore it
            else if (note == '\n' || note == '\r')
            {
                return;
            }
            //If it didn't match any case, it must be a normal note
            else
            {
                WindowsInput.Native.VirtualKeyCode vk;
                try
                {
                    VirtualDictionary.TryGetValue(char.ToUpper(note), out vk);

                    if (vk == 0)
                    {
                        return;
                    }
                }
                catch (ArgumentNullException)
                {
                    return;
                }

                //This will check if the note is an uppercase letter, or if the note is in the list of high notes
                bool isHighNote = char.IsUpper(note) || AlwaysHighNotes.Contains(note);

                if (buildingMultiNote)
                {
                    if (multiNoteBuffer.Count == 0)
                    {
                        multiNoteIsHighNote = char.IsUpper(note) || AlwaysHighNotes.Contains(note);
                    }

                    if (isHighNote != multiNoteIsHighNote)
                    {
                        throw new AutoplayerNoteCreationFailedException($"A multinote cannot contain both high and low keys!");
                    }

                    multiNoteBuffer.Add(new Note(note, vk, isHighNote));
                }
                else
                {
                    Song.Add(new Note(note, vk, isHighNote));
                }
            }
        }
Ejemplo n.º 14
0
    static void ProcessSongComponentLine(string line, Song song, List <Anchor> anchorData)
    {
        int stringViewIndex = 0;

        uint position = HackyStringViewFunctions.GetNextTick(line, ref stringViewIndex);

        HackyStringViewFunctions.AdvanceChartLineStringView(line, ref stringViewIndex);  // Skip over the equals sign
        char type = line[stringViewIndex];

        HackyStringViewFunctions.AdvanceChartLineStringView(line, ref stringViewIndex);

        switch (type)
        {
        case 'B':
        {
            uint value = HackyStringViewFunctions.AdvanceStringToUInt(line, ref stringViewIndex);
            song.Add(new BPM(position, value), false);
        }
        break;

        case 'T':
        {
            uint numerator = HackyStringViewFunctions.AdvanceStringToUInt(line, ref stringViewIndex);

            TimeSignature ts = new TimeSignature(position, numerator);
            song.Add(ts, false);

            if (stringViewIndex < line.Length)
            {
                uint denominator = HackyStringViewFunctions.AdvanceStringToUInt(line, ref stringViewIndex);

                denominator    = (uint)(Mathf.Pow(2, denominator));
                ts.denominator = denominator;
            }
        }
        break;

        case 'E':
        {
            string       text       = HackyStringViewFunctions.GetNextTextUpToQuote(line, ref stringViewIndex);
            const string SECTION_ID = "section";

            // Check if it's a section
            if (string.Compare(text, 0, SECTION_ID, 0, SECTION_ID.Length) == 0)
            {
                text = text.Remove(0, SECTION_ID.Length);
                text = text.Trim();
                song.Add(new Section(text, position), false);
            }
            else
            {
                song.Add(new Event(text, position), false);
            }
        }
        break;

        case 'A':
        {
            uint   anchorValue = HackyStringViewFunctions.AdvanceStringToUInt(line, ref stringViewIndex);
            Anchor a;
            a.position   = position;
            a.anchorTime = (float)(anchorValue / 1000000.0d);
            anchorData.Add(a);
        }
        break;

        default:
            return;
        }
    }