Exemple #1
0
 public Part(MusicTheory theory, Random rand, Rhythm rhythm, int rhythmNumber, Melody melody, int melodyNumber, int measureLength, double rhythmCrowdedness, double noteLengthAdjustment, double regularity, int lowerPitchLimit, int octaveRange, bool forceChord, bool forceDiatonic)
     : this(theory, rand, rhythm, rhythmNumber, melody, melodyNumber, measureLength)
 {
     this.rhythmCrowdedness = rhythmCrowdedness;
     this.noteLengthAdjustment = noteLengthAdjustment;
     this.regularity = regularity;
     this.lowerPitchLimit = lowerPitchLimit;
     this.octaveRange = octaveRange;
     this.forceChord = forceChord;
     this.forceDiatonic = forceDiatonic;
 }
Exemple #2
0
        /// <summary>
        /// cTor: create from a number of values
        /// </summary>
        /// <param name="melody">Melody to play from</param>
        /// <param name="note">The Note to play</param>
        /// <param name="loops">Loops to add (max 5)</param>
        /// <param name="volume">Volume to play with (default = 1.0)</param>
        /// <param name="speed">Speed Factor (default = 1.0)</param>
        public SoundBite(Melody melody, uint note, uint loops, float volume = 1.0f, float speed = 1.0f)
        {
            Melody = melody;
            var tune = WaveProc.GetInstalledSounds().Where(x => x.Melody == melody).FirstOrDefault();

            if (tune == null)
            {
                // sould not happen .....
                LOG.LogError($"SoundBite: Cannot find the Melody: {melody}");
                Melody = Melody.Silence;
                return;
            }

            Tone      = (note < tune.NumTones) ? note : note % tune.NumTones; // safeguard Note
            Volume    = (volume >= 0) ? volume : 0;                           // must be >= 0.0
            Loops     = (loops <= 5) ? loops : 5;                             // must be <= 5
            SpeedFact = (speed > 0) ? speed : 1;                              // must be > 0.0
        }
        public static Dictionary <Pattern, List <Occurrence> > FindPatternsOfTypeInSong(
            Song song,
            int version,
            PatternType patternType,
            int minLengthToSearch = 3,
            int maxLengthToSearch = 12)
        {
            var retObj = new Dictionary <Pattern, List <Occurrence> >();

            foreach (var instr in song.SongStats.Instruments)
            {
                var notes       = song.SongSimplifications[version].NotesOfInstrument(instr);
                var voicesNotes = Utilities.GetVoices(notes.ToList());
                foreach (var voice in voicesNotes.Keys)
                {
                    var melody   = new Melody(voicesNotes[voice]);
                    var elements = new List <string>();
                    switch (patternType)
                    {
                    case PatternType.Pitch:
                        elements = melody.DeltaPitchesAsStrings;
                        break;

                    case PatternType.Rythm:
                        elements = melody.DurationsInTicksAsStrings;
                        break;

                    case PatternType.Melody:
                        elements = melody.AsListOfStrings.ToList();
                        break;
                    }
                    var patterns = FindPatternsInListOfStrings(elements, minLengthToSearch, maxLengthToSearch);
                    foreach (var pat in patterns)
                    {
                        var patito = new Pattern()
                        {
                            AsString = pat.Key, PatternTypeId = patternType
                        };
                        var ocur = new List <Occurrence>();
                        foreach (var oc in pat.Value)
                        {
                            var firstNote     = melody.Notes[oc];
                            var patternLength = pat.Key.Split(",").Length;
                            var ocNotes       = melody.Notes.ToArray()[oc..(oc + patternLength)].ToList();
    IEnumerator AddAndPlay(int seconds = 2)
    {
        SetState(GameState.PC);

        yield return(new WaitForSeconds(seconds));

        b12.color = new Color(255, 255, 255, 0.1F);
        Melody selected_melody = PickOne();

        melody_sheet.Add(selected_melody);
        foreach (Melody melody in melody_sheet)
        {
            melody.Play();
            yield return(new WaitForSeconds(.7F));
        }
        SetState(GameState.USER);
        StopCoroutine("AddAndPlay");
        yield break;
    }
Exemple #5
0
        public void SpawnNote(string note, Melody melody)
        {
            Transform parent;

            switch (note)
            {
            case "_":
            case "*":
                return;

            case "-":
                melody.score.Value += 1;
                return;

            case "1":
                parent = m1;
                break;

            case "2":
                parent = m2;
                break;

            case "3":
                parent = m3;
                break;

            case "4":
                parent = m4;
                break;

            default:
                Debug.Log("warning : tried to spawn a note of unkown type : [" + note + "]");
                return;
            }

            GameObject noteObj = Instantiate(notePrefab, parent);

            noteObj.GetComponent <Note>().note      = int.Parse(note);
            noteObj.GetComponent <Note>().melody    = melody;
            noteObj.GetComponent <NoteMove>().speed = 2f;
            noteObj.GetComponentInChildren <TextMeshProUGUI>().text = note;
        }
    public void CheckUserSelect(Melody user_selected)
    {
        Melody melody = melody_sheet[user_melody_index];

        if (melody.unique_name == user_selected.unique_name)
        {
            user_melody_index++;
            if (user_melody_index >= melody_sheet.Count)
            {
                user_melody_index = 0;
                score_manager.Add();
                b12.color = new Color(255, 255, 255, 1);
                StartCoroutine(AddAndPlay(2));
            }
        }
        else
        {
            GameOver();
        }
    }
Exemple #7
0
        public void SelectMelody(Melody melody, CharacterControl target = null)
        {
            if (!instruments.Any(instrument => instrument.melodies.Contains(melody)))
            {
                Debug.Log("Warning : Melody [" + melody.name + "] is not equipped");
                return;
            }

            if (!melody.isPlayable.Value)
            {
                Debug.Log("Warning : Melody [" + melody.name + "] is not playable");
                return;
            }

            SetActionPlayableMelodies();
            SetInspirationPlayableMelodies();

            if (_selectedInstrumentIndex == 0)   //if no instrument was selected
            //select melody's instrument
            {
                _selectedInstrumentIndex = instruments.FindIndex(i => i.melodies.Contains(melody));
            }

            //if an instrument is selected
            if (_selectedInstrumentIndex != 0)
            {
                //make other instrument melodies unplayable
                int unselected = _selectedInstrumentIndex == 1 ? 2 : 1;
                foreach (Melody m in instruments[unselected].melodies)
                {
                    m.isPlayable.Value = false;
                }
            }

            selectedMelodies.Add(melody);
            actionPoints.Value -= melody.Size;
            inspiration.SelectMelody(melody);

            melody.isPlayable.Value = false;
            melody.target           = target;
        }
Exemple #8
0
    //メロディ取得
    public Melody Get_Now_Melody()
    {
        now_BGM_Time = (Time.unscaledTime - BGM_Launch_Time) % BGM_TIME[BGM_TIME.Length - 1];

        if (now_BGM_Time < BGM_TIME[1])
        {
            if (now_Melody != Melody.A)
            {
                now_Melody = Melody.A;
            }
        }
        else if (now_BGM_Time < BGM_TIME[2])
        {
            if (now_Melody != Melody.B)
            {
                now_Melody = Melody.B;
            }
        }
        else if (now_BGM_Time < BGM_TIME[3])
        {
            if (now_Melody != Melody.A)
            {
                now_Melody = Melody.A;
            }
        }
        else if (now_BGM_Time < BGM_TIME[4])
        {
            if (now_Melody != Melody.C)
            {
                now_Melody = Melody.C;
            }
        }
        else if (now_BGM_Time < BGM_TIME[6])
        {
            if (now_Melody != Melody.main)
            {
                now_Melody = Melody.main;
            }
        }
        return(now_Melody);
    }
Exemple #9
0
        public void Mutate(Melody melody)
        {
            var randomRate = ThreadSafeRandom.ThisThreadsRandom.Next(0, 100);

            if (randomRate < Rate)
            {
                var indexA = ThreadSafeRandom.ThisThreadsRandom.Next(melody.Measures.Count);
                var indexB = ThreadSafeRandom.ThisThreadsRandom.Next(melody.Measures.Count);

                while (indexB == indexA)
                {
                    indexB = ThreadSafeRandom.ThisThreadsRandom.Next(melody.Measures.Count);
                }

                // Before swap changes order
                var orderA = melody.Measures[indexA].Order;
                melody.Measures[indexA].Order = melody.Measures[indexB].Order;
                melody.Measures[indexB].Order = orderA;

                melody.Measures.Swap(indexA, indexB).ToList();
            }
        }
Exemple #10
0
        public Part(MusicTheory theory, Random rand, Rhythm rhythm, int rhythmNumber, Melody melody, int melodyNumber, int measureLength)
        {
            //Get instance of InputParameters
            InputParameters inputParameters = InputParameters.Instance;

            this.theory = theory;
            this.rand = rand;
            this.rhythm = rhythm;
            this.rhythmNumber = rhythmNumber;
            this.melody = melody;
            this.melodyNumber = melodyNumber;
            this.measureLength = measureLength;

            //Set rhythm crowdedness based on input parameters
            rhythmCrowdedness = inputParameters.MeanPartRhythmCrowdedness + (inputParameters.MeanPartRhythmCrowdedness * (rand.NextDouble() - 0.5) * inputParameters.PartRhythmCrowdednessVariance);

            //Set note length adjustment based on input parameters
            noteLengthAdjustment = 0.5 + (0.5 * (rand.NextDouble() - 0.5) * inputParameters.PartNoteLengthVariance);

            //Set octave range based on input parameters
            octaveRange = (int)Math.Round(theory.PART_OCTAVE_RANGE * inputParameters.MeanPartOctaveRange);
            octaveRange += (int)Math.Round(octaveRange * (rand.NextDouble() - 0.5) * inputParameters.PartOctaveRangeVariance);
            octaveRange = (int)MathHelper.Clamp(octaveRange, 1, Automatone.PIANO_SIZE / 12);

            //Set random lower pitch limit
            lowerPitchLimit = rand.Next(Automatone.PIANO_SIZE - (octaveRange * MusicTheory.OCTAVE_SIZE)) + Automatone.LOWEST_NOTE_CHROMATIC_NUMBER;

            forceChord = false;
            forceDiatonic = false;

            //Set regularity based on input parameters
            regularity = 0;
            if (rand.NextDouble() < inputParameters.BeatDefinition)
            {
                forceChord = true;
                regularity = rand.NextDouble();
            }
        }
Exemple #11
0
        public Melody Cross(Melody firstParent, Melody secondParent)
        {
            var measuresCount     = firstParent.Measures.Count;
            var numberOfFirstTake = ThreadSafeRandom.ThisThreadsRandom.Next(measuresCount + 1);
            var firstMeasures     = firstParent.Measures.Take(numberOfFirstTake).ToList();
            var secondMeasures    = secondParent.Measures.Skip(numberOfFirstTake).Take(measuresCount - numberOfFirstTake).ToList();
            var childMeasures     = new List <Measure>();

            childMeasures.AddRange(firstMeasures);
            childMeasures.AddRange(secondMeasures);

            for (var i = 0; i < childMeasures.Count; i++)
            {
                _measureMutationOperators.ForEach(m => m.Mutate(childMeasures[i]));
                childMeasures[i].Order = i;
            }

            var melody = new Melody(childMeasures, firstParent.TimeMap);

            _melodyMutationOperators.ForEach(m => m.Mutate(melody));

            return(melody);
        }
Exemple #12
0
        private List <int> GetDifferentIntervals(Melody melody)
        {
            var differentInvervals = new List <int>();
            var notes = melody.Measures.SelectMany(m => m.Events).OfType <Note>().ToList();

            Note previous = null;

            foreach (var note in notes)
            {
                if (previous != null)
                {
                    var interval = Math.Abs(previous.Number - note.Number);

                    if (interval > 0 && !differentInvervals.Contains(interval))
                    {
                        differentInvervals.Add(interval);
                    }
                }

                previous = note;
            }

            return(differentInvervals);
        }
Exemple #13
0
 public abstract IInteractionMode Sing(Melody melody);
Exemple #14
0
 public override IInteractionMode Sing(Melody melody) =>
 Start().Sing(melody);
Exemple #15
0
 /// <summary>
 /// Plays the melody.
 /// </summary>
 /// <param name="melody">The melody to play.</param>
 public void Play(Melody melody)
 {
     this.playList = melody;
     this.Play();
 }
Exemple #16
0
 public WaitingState(Melody inst) : base(inst)
 {
     inst.aSrc.Stop();
     startTime = currentTime;
 }
Exemple #17
0
 public StopState(Melody inst) : base(inst)
 {
     inst.aSrc.Stop();
 }
        public static Fingering CreateFingeringFor(this FingerboardInstrument instrument, Melody piece, ISelectValue randomness)
        {
            var notes = piece.Notes;

            var fingering = new Fingering();

            foreach (Note p in notes)
            {
                var possibleAlternatives = instrument.PositionsFor(p);

                int            randomIndex = randomness.BetweenZeroAnd(possibleAlternatives.Count - 1);
                FingerPosition selected    = possibleAlternatives[randomIndex];

                fingering.Add(new FingerPosition(selected.Fret, selected.String));
            }

            return(fingering);
        }
        public static Dictionary <Pattern, List <Occurrence> > FindPatternsOfTypeInSong(
            Song song,
            int version,
            PatternType patternType,
            int minLengthToSearch = 3,
            int maxLengthToSearch = 50)
        {
            var retObj = new Dictionary <Pattern, List <Occurrence> >();

            foreach (var instr in song.Instruments)
            {
                var notes       = song.Versions[0].NotesOfInstrument(instr);
                var voicesNotes = GetVoices(notes);
                foreach (var voice in voicesNotes.Keys)
                {
                    var melody   = new Melody(voicesNotes[voice]);
                    var elements = new List <string>();
                    switch (patternType)
                    {
                    case PatternType.Pitch:
                        elements = melody.DeltaPitchesAsStrings;
                        break;

                    case PatternType.Rythm:
                        elements = melody.DurationsInTicksAsStrings;
                        break;

                    case PatternType.Melody:
                        elements = melody.AsListOfStrings.ToList();
                        break;
                    }
                    var patterns = FindPatternsInListOfStrings(elements, minLengthToSearch, maxLengthToSearch);
                    foreach (var pat in patterns)
                    {
                        var patito = new Pattern()
                        {
                            AsString = pat.Key, PatternTypeId = patternType
                        };
                        var ocur = new List <Occurrence>();
                        foreach (var oc in pat.Value)
                        {
                            var firstNote = melody.Notes[oc];
                            var noteOfSongCorrespondingToFirstNote = FindNoteOfSong(firstNote, song, version, instr);
                            var patternLength = pat.Key.Split(",").Length;
                            var lastNote      = melody.Notes[oc + patternLength];
                            var noteOfSongCorrespondingToLastNote = FindNoteOfSong(lastNote, song, version, instr);

                            var o = new Occurrence()
                            {
                                Pattern       = patito,
                                FirstNoteId   = noteOfSongCorrespondingToFirstNote.Id,
                                LastNoteId    = noteOfSongCorrespondingToLastNote.Id,
                                SongVersionId = song.Versions[version].Id
                            };
                            ocur.Add(o);
                        }
                        retObj[patito] = ocur;
                    }
                }
            }
            return(SimplifyPatterns(retObj));
        }
 public void AddUsableMelody(Melody melody)
 {
     usable_melodies.Add(melody);
 }
Exemple #21
0
 public SongSegment(List <Chord> chordPattern, List <Melody> melodies, Melody dontInclude)
 {
     this.chordPattern = chordPattern;
     this.melodies     = melodies;
     this.melodies.Remove(dontInclude);
 }
 //時間計測開始
 public void Start_Time_Count()
 {
     BGM_Launch_Time = Time.unscaledTime;
     now_Melody      = melody_List[0].melody;
 }
Exemple #23
0
 public void Sing(Melody melody) =>
 Execute(InteractionMode.Sing(melody));
Exemple #24
0
 public SongSegment(List<Chord> chordPattern, List<Melody> melodies, Melody dontInclude)
 {
     this.chordPattern = chordPattern;
     this.melodies = melodies;
     this.melodies.Remove(dontInclude);
 }
Exemple #25
0
    private void AddSubscription(List <IDisposable> subscriptions, Bard.Bard bard, CharacterControl character, Melody melody)
    {
        subscriptions.Add(
            character.gameObject.OnMouseDownAsObservable()
            .Subscribe(__ => {
            bard.SelectMelody(melody, character);
            subscriptions.ForEach(s => s.Dispose());

            foreach (CharacterControl chara
                     in CombatManager.Instance.teams.SelectMany(team => team))
            {
                chara.gameObject.transform.Find("HighLight").gameObject.SetActive(false);
            }
        }));
    }
Exemple #26
0
 /// <summary>
 /// Plays the melody.
 /// </summary>
 /// <param name="melody">The melody to play.</param>
 public void Play(Melody melody)
 {
     _playList = melody;
     Play();
 }
Exemple #27
0
 public override IInteractionMode Sing(Melody melody) =>
 Sing(Song.Define(SongNumber.Immediate, melody)).Play(SongNumber.Immediate);
Exemple #28
0
 public RandomInitializer(Melody melody)
 {
     BaseMelody = melody;
 }
Exemple #29
0
    // Use this for initialization
    void Awake()
    {
        instance = this;

        rBPM   = 60f / BPM;
        oldBPM = BPM;
        songs  = new List <Song>();

        drums  = GetComponentInChildren <Drums>();
        synth  = GetComponentInChildren <Synth>();
        melody = GetComponentInChildren <Melody>();

        //load all songs
        int  count = 1;
        bool run   = true;

        while (run)
        {
            string path = Path.Combine(Application.streamingAssetsPath, "Songs/" + count.ToString() + ".txt");

            if (File.Exists(path))
            {
                string[] lines   = File.ReadAllLines(path);
                Song     newSong = new Song();

                for (int i = 0; i < lines.Length; ++i)
                {
                    if (lines[i].Length == 0)
                    {
                        break;
                    }

                    if (lines[i][0] == '_')
                    {
                        int x = i + 1;
                        while (x < lines.Length && lines[x].Length > 0 && lines[x][0] != '_')
                        {
                            switch (lines[i])
                            {
                            case "_synth":
                                newSong.synth.Add(lines[x]);
                                //Debug.Log("Added synth");
                                break;

                            case "_melody":
                                newSong.melody.Add(lines[x]);
                                //Debug.Log("Added melody");
                                break;

                            case "_drums":
                                newSong.drums.Add(lines[x]);
                                //Debug.Log("Added drums");
                                break;
                            }
                            x++;
                        }
                    }
                }

                songs.Add(newSong);
            }
            else
            {
                run = false;
            }

            count++;
        }

        if (songs.Count == 0)
        {
            enabled = false;
            return;
        }

        Song s = SelectRandomSong();

        DoSong(s);
    }
Exemple #30
0
 public PlayingState(Melody inst) : base(inst)
 {
     inst.aSrc.Play();
     BGM.StopInstThemes();
 }