Beispiel #1
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 #2
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 #3
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 #4
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);
    }