Beispiel #1
0
    public Chord GetChord()
    {
        Debug.Log("Measure.GetChord " + chord.GetBass());
        Chord ch = new Chord(chord.GetNotes());

        ch.SetBass(chord.GetBass());
        ch.SetChordName(chord.GetChordName());
        ch.SetChordText(chord.GetChordText());
        Debug.LogWarning("GetChord " + ch.GetNotes().Count + " / chord " + chord.GetNotes().Count);
        return(ch);
    }
Beispiel #2
0
    /// <summary>
    /// 화음에서 특정 음(before)을 다른 음(after)으로 바꾸어 반환합니다.
    /// </summary>
    /// <param name="chord"></param>
    /// <param name="before"></param>
    /// <param name="after"></param>
    /// <returns></returns>
    static Chord ReviseNote(Chord chord, int before, int after)
    {
        Chord newChord = new Chord();

        newChord.SetChordName(chord.GetChordName());
        newChord.SetChordText(chord.GetChordText());
        newChord.SetBass(chord.GetBass());
        foreach (int n in chord.GetNotes())
        {
            if (n == before)
            {
                newChord.AddNote(after);
            }
            else
            {
                newChord.AddNote(n);
            }
        }
        Debug.Log("Chord ReviseNote " + newChord.GetBass());
        if (chord.GetBass() == before)
        {
            newChord.SetBass(after);
        }
        else
        {
            newChord.SetBass(chord.GetBass());
        }
        return(newChord);
    }
Beispiel #3
0
        private static void VerifySecondInversion(Chord chord)
        {
            var notes = chord.GetNotes();

            notes[0].Value.Should().Be(55); // C4
            notes[1].Value.Should().Be(60); // E4
            notes[2].Value.Should().Be(64); // G3
        }
Beispiel #4
0
        public void Test_adding_new_chord_type()
        {
            Chord.ChordMap["POW"] = new Intervals("1 5");
            var chord = new Chord("Cpow");
            var notes = chord.GetNotes();

            notes[0].Value.Should().Be(48); //C3
            notes[1].Value.Should().Be(55); //G3
        }
Beispiel #5
0
    public void WriteChord()
    {
        if (!Manager.manager.GetIsThereFirstChord())
        {
            Manager.manager.SetIsThereFirstChord();
        }

        int measureNum = Manager.manager.GetCursorMeasureNum();

        Manager.manager.SetCursor(Manager.manager.GetStaff(2).GetMeasure(measureNum), measureNum);
        Manager.manager.GetStaff(1).GetMeasure(measureNum).ClearMeasure();
        Manager.manager.GetStaff(2).GetMeasure(measureNum).ClearMeasure();
        Color color = new Color(0, 0, 0, 0.3f);

        foreach (int c in chord.GetNotes())
        {
            if (c < 0 || c > 40)
            {
                continue;
            }
            Manager.manager.WriteNote(2, measureNum, c, "온음표", 0);
        }
        Manager.manager.WriteNote(1, measureNum, chord.GetNotes()[0], "4분음표", 0, color, true);
        Manager.manager.WriteNote(1, measureNum, chord.GetNotes()[0], "4분음표", 4, color, true);
        Manager.manager.WriteNote(1, measureNum, chord.GetNotes()[0], "4분음표", 8, color, true);
        Manager.manager.WriteNote(1, measureNum, chord.GetNotes()[0], "4분음표", 12, color, true);
        Debug.Log("ChordButton WriteChord " + chord.GetBass());
        Manager.manager.GetStaff(2).GetMeasure(measureNum).SetChord(chord);

        Manager.manager.GetStaff(1).GetMeasure(measureNum).InteractionOn();
        // Manager.manager.GetStaff(0).GetMeasure(measureNum).InteractionOn();
        if (firstTime)
        {
            firstTime = false;
            Finder.finder.instructionPanel0.SetActive(true);
            Finder.finder.darkPanel.SetActive(true);
        }
    }
Beispiel #6
0
    /// <summary>
    /// 화음의 음들이 악보에 겹치지 않고 표시되면 true, 겹쳐서 표시되면 false를 반환합니다.
    /// </summary>
    /// <param name="chord"></param>
    /// <returns></returns>
    public static bool CheckScoreNotation(Chord chord, bool isTreble)
    {
        List <int> notes = chord.GetNotes();

        for (int i = 0; i < notes.Count; i++)
        {
            for (int j = 0; j < i; j++)
            {
                if (Mathf.Abs(Note.NoteToScore(notes[i], isTreble) - Note.NoteToScore(notes[j], isTreble)) <= 0.125f)
                {
                    return(false);
                }
            }
        }
        return(true);
    }
        public string Apply(string parameters, StaccatoParserContext context)
        {
            var    chord           = new Chord(parameters);
            var    notes           = chord.GetNotes();
            double duration        = chord.Root.Duration;
            double durationPerNote = duration / notes.Length;
            var    sb = new StringBuilder();

            foreach (var note in notes)
            {
                sb.Append(Note.GetToneString(note.Value));
                sb.Append("/");
                sb.Append(durationPerNote);
                sb.Append(" ");
            }
            return(sb.ToString().Trim());
        }
Beispiel #8
0
    /// <summary>
    /// 화음의 음들이 악보에 겹치지 않고 표시될 수 있도록 음의 위치를 보정합니다.
    /// 만약 한 옥타브 내에서 겹칠 수밖에 없는 화음이라면 다른 옥타브로도 음을 옮겨봅니다.
    /// 보정을 완료하고 그 화음을 반환합니다.
    /// isTreble은 낮은음자리표이면 false를, 높은음자리표이면 true를 넣습니다.
    /// 악보에서 겹친다는 뜻은 두 음의 y좌표가 0.125 이하만큼 차이 난다는 뜻입니다.
    /// </summary>
    /// <param name="chord"></param>
    /// <returns></returns>
    public static Chord ReviseScoreNotation(Chord chord, bool isTreble)
    {
        //if (CheckScoreNotation(chord)) return chord;
        List <Chord> enumerated = new List <Chord>();
        List <Chord> temp       = new List <Chord>();
        Chord        initChord  = new Chord();

        initChord.SetChordName(chord.GetChordName());
        initChord.SetChordText(chord.GetChordText());
        initChord.SetBass(chord.GetBass());

        // Initialize (half moving)
        foreach (int n in chord.GetNotes())
        {
            if (Note.NoteToAccidental(n) == 2) // b이면
            {
                initChord.AddNote(n - 1);      // #으로 통일
            }
            else
            {
                initChord.AddNote(n);
            }
        }
        Debug.Log("Chord ReviseScoreNotation " + initChord.GetBass());

        for (int i = 0; i < initChord.GetNotes().Count; i++)
        {
            if (isTreble && (initChord.GetNotes()[i] / 17 < 2 ||
                             initChord.GetNotes()[i] / 17 > 3))
            {
                initChord = ReviseNote(initChord, initChord.GetNotes()[i],
                                       initChord.GetNotes()[i] % 17 + 34);
            }
            else if (!isTreble && (initChord.GetNotes()[i] / 17 < 0 ||
                                   initChord.GetNotes()[i] / 17 > 1))
            {
                initChord = ReviseNote(initChord, initChord.GetNotes()[i],
                                       initChord.GetNotes()[i] % 17 + 17);
            }
        }

        // Enumerate all possible cases (half moving)
        enumerated.Add(initChord);
        for (int i = 0; i < initChord.GetNotes().Count; i++)
        {
            if (Note.NoteToAccidental(initChord.GetNotes()[i]) == 1)
            {
                temp.Clear();
                foreach (Chord c in enumerated)
                {
                    temp.Add(ReviseNote(c, initChord.GetNotes()[i], initChord.GetNotes()[i] + 1));
                }
                foreach (Chord t in temp)
                {
                    enumerated.Add(t);
                }
            }
        }

        // Check each case (half moving)
        foreach (Chord c in enumerated)
        {
            //Debug.Log("enumerated " + c.NotesName());
            if (CheckScoreNotation(c, isTreble))
            {
                return(c);
            }
        }

        // 반음 조절로 실패한 경우 옥타브 조절을 시도
        initChord = new Chord();
        enumerated.Clear();
        initChord.SetChordName(chord.GetChordName());
        initChord.SetChordText(chord.GetChordText());
        initChord.SetBass(chord.GetBass());

        // Initialize (octave moving)
        foreach (int n in chord.GetNotes())
        {
            initChord.AddNote((n % 17) + 17);
        }

        // Enumerate all possible cases (octave moving)
        enumerated.Add(initChord);
        for (int i = initChord.GetNotes().Count - 1; i >= 0; i--)
        {
            if (initChord.GetNotes()[i] / 17 == 1)
            {
                temp.Clear();
                foreach (Chord c in enumerated)
                {
                    temp.Add(ReviseNote(c, initChord.GetNotes()[i], initChord.GetNotes()[i] - 17));
                }
                foreach (Chord t in temp)
                {
                    enumerated.Add(t);
                }
            }
        }

        // Check each case (octave moving)
        foreach (Chord c in enumerated)
        {
            //Debug.Log("octave enumerated " + c.NotesName());
            if (CheckScoreNotation(c, isTreble))
            {
                return(c);
            }
        }
        return(null);
    }
        public string Preprocess(string musicString, StaccatoParserContext context)
        {
            var retVal = new StringBuilder();

            var splitsville = musicString.Split(' ');

            foreach (string s in splitsville)
            {
                int posColon = 0;
                if ((posColon = s.IndexOf(':')) != -1 && (posColon > 0))
                {
                    string candidateChord = s.Substring(0, posColon);

                    // We don't want to think we have a chord when we really have a key signature or time signature, or
                    // we have a tuplet (indicated by the asterisk)
                    if (Chord.IsValid(candidateChord))
                    {
                        Chord chord = new Chord(candidateChord);

                        // Get the replacement description
                        int    posColon2 = s.FindNextOrEnd(':', posColon + 1);
                        string replacementDescription = s.Substring(posColon + 1, posColon2 - posColon - 1);
                        string dynamics = (posColon2 == s.Length ? "" : s.Substring(posColon2 + 1, s.Length - posColon2 - 1));

                        // If the replacement description starts with a bracket, look up the value in the context's dictionary
                        if (replacementDescription[0] == '[')
                        {
                            var replacementLookup = replacementDescription.Substring(1, replacementDescription.Length - 2);
                            replacementDescription = context.Dictionary[replacementLookup] as string;
                        }

                        var specialReplacers = new Dictionary <string, IPatternProducer>
                        {
                            ["ROOT"]    = chord.Root,
                            ["BASS"]    = chord.GetBassNote(),
                            ["NOTROOT"] = WrapInParens(chord.GetPatternWithNotesExceptRoot())
                        };

                        specialReplacers["NOTBASS"] = WrapInParens(chord.GetPatternWithNotesExceptBass());

                        var result = ReplacementFormatUtil.ReplaceDollarsWithCandidates(
                            replacementDescription,
                            chord.GetNotes(),
                            WrapInParens(chord.GetPatternWithNotes()),
                            specialReplacers,
                            ",",
                            " ",
                            dynamics
                            );
                        retVal.Append(result);
                    }
                    else
                    {
                        retVal.Append(s);
                    }
                }
                else
                {
                    retVal.Append(s);
                }
                retVal.Append(" ");
            }
            return(retVal.ToString().Trim());
        }
        public void Test_replacement_with_long_special_map_keys()
        {
            var chord      = new Chord("Cmaj");
            var specialMap = new Dictionary <string, IPatternProducer>
            {
                ["URANUS"]  = new Pattern("C D E F"),
                ["NEPTUNE"] = new Pattern("A B Ab B"),
                ["JUPITER"] = new Pattern("C G C G"),
                ["MARS"]    = new Pattern("F E D C")
            };

            var result = ReplacementFormatUtil.ReplaceDollarsWithCandidates("$0q,$1h,$2w,$URANUSq,Rq,$NEPTUNEq,$!q", chord.GetNotes(), chord, specialMap, ",", " ", ".");

            result.ToString().Should().Be("Cq. Eh. Gw. Cq. Dq. Eq. Fq. Rq. Aq. Bq. Abq. Bq. CMAJq.");
        }
        public void Test_underscores_and_plus()
        {
            var chord = new Chord("Cmaj");

            var result = ReplacementFormatUtil.ReplaceDollarsWithCandidates("$0q+$1q $2h $1h+$2q_$0q", chord.GetNotes(), chord);

            result.ToString().Should().Be("Cq+Eq Gh Eh+Gq_Cq");
        }
        public void Test_replacement_with_chord()
        {
            var chord = new Chord("Cmaj");

            var result = ReplacementFormatUtil.ReplaceDollarsWithCandidates("$0q $1h $2w $!q", chord.GetNotes(), chord);

            result.ToString().Should().Be("Cq Eh Gw CMAJq");
        }