//given a markov chain, step through the process of creating news notes like a finite-state-machine.
    private Dictionary <int, List <GridManager.Notes> > generateMarkovNotes(Dictionary <int, List <GridManager.Notes> > input, Dictionary <GridManager.Notes, ChainLink> markovChain, Dictionary <int, List <GridManager.Notes> > markovNotes)
    {
        wipeDict(markovNotes);

        //int startingBeat = getEndOfInput(input)+4;
        int startingBeat = 0;
        List <GridManager.Notes> allNotes = getAllNotesOfInput(input);

        GridManager.Notes nextNote = allNotes[random.Next(allNotes.Count)];
        markovNotes[startingBeat].Add(nextNote);
        for (int i = startingBeat + 4; i < markovNotes.Count; i += 4)
        {
            nextNote = markovChain[nextNote].getNextNote();

            if (markovChordProduction)
            {
                markovNotes[i].Add(nextNote);
                if (i % 16 == 0)
                {
                    foreach (GridManager.Notes note in generateChord(nextNote))
                    {
                        if (nextNote != note)
                        {
                            markovNotes[i].Add(note);
                        }
                    }
                }
            }
            else
            {
                markovNotes[i].Add(nextNote);
            }
        }
        return(markovNotes);
    }
    //given dictionary to populate and what bar the system is currently on, randomly add and randomly remove notes from the passed dictionary.
    private Dictionary <int, List <GridManager.Notes> > generateRandomNotes(Dictionary <int, List <GridManager.Notes> > randomNotes, int bar)
    {
        int numberOfNotesAdded   = 0;
        int numberOfNotesRemoved = 0;

        System.Random randomNoteChooser = new System.Random();
        foreach (KeyValuePair <int, List <GridManager.Notes> > pair in randomNotes)
        {
            GridManager.Notes newRandomNote = GridManager.Notes.none;
            int r = randomNoteChooser.Next(0, 100);
            if (pair.Value.Count != 0)
            {
                if (r > 10)
                {
                    numberOfNotesRemoved += 1;
                    pair.Value.RemoveAt(0);
                }
            }
            if (r > (Mathf.Max(bar, 20)))
            {
                numberOfNotesAdded += 1;
                newRandomNote       = getRandomNoteInKey();
                pair.Value.Add(newRandomNote);
            }
        }
        print("Number Of Notes Added: " + numberOfNotesAdded);
        print("Number Of Notes Removed: " + numberOfNotesRemoved);
        return(randomNotes);
    }
Ejemplo n.º 3
0
 //method used to return the sound variables of a vertex.
 public void formatVertex(out GridManager.Notes note, out float timing, out float volume, out float length, out string voice)
 {
     note   = getVertexNote();
     timing = getVertexTiming();
     volume = getVertexVolume();
     length = getVertexLength();
     voice  = "Voice" + getParentsLineManager().getVoice().ToString();
 }
 public void addToPath(GridManager.Notes newNote)
 {
     if (!paths.ContainsKey(newNote))
     {
         paths.Add(newNote, 1f);
     }
     else
     {
         paths[newNote] += 1f;
     }
 }
Ejemplo n.º 5
0
 //method used to call methods to show note boundaries if they have been "passed".
 private void noteBoundaryUpdate(GridManager.Notes vertexNote)
 {
     if (lastVertexNote != GridManager.Notes.none)
     {
         if (lastVertexNote != vertexNote)
         {
             gridManager.showNoteBoundaries(lastVertexNote, vertexNote);
         }
     }
     setLastVertexNote(vertexNote);
 }
Ejemplo n.º 6
0
 //send a message to the OSC Client
 public static void contactSC(GridManager.Notes note, float volume, float length, string voice)
 {
     if (voice != "None")
     {
         //OSC Send
         List <string> args = new List <string>();
         args.Add(volume.ToString());
         args.Add(GridManager.noteToFreq[note].ToString());
         args.Add(length.ToString());
         OSCHandler.Instance.SendMessageToClient("SuperCollider", "/play" + voice, args);
     }
 }
    void Update()
    {
        //key has been changed and available notes needs to change
        if (lastKey != key && key != GridManager.Notes.none)
        {
            setAvailableNotes();
        }

        //start playing the master score.
        if (playButton)
        {
            if (coroutine == null)
            {
                coroutine = StartCoroutine(playInput());
            }
        }

        //play all the available notes.
        if (playScaleButton && key != GridManager.Notes.none)
        {
            StartCoroutine(playScale());
            playScaleButton = false;
        }

        //call the calculate key method.
        if (calculateKeyButton)
        {
            calculateKey();
            calculateKeyButton = false;
        }

        //take the notes in notesToInput, and convert them to GridManager.Notes
        if (inputNotes)
        {
            List <GridManager.Notes> inputAsNotes = convertStringToNotes(notesToInput);
            notesToInput = "";
            inputNotes   = false;
            int index = 0;
            foreach (GridManager.Notes note in inputAsNotes)
            {
                if (note != GridManager.Notes.none)
                {
                    masterScore[index].Add(note);
                }
                index += 4;
            }
        }
        lastKey = key;
    }
    private List <GridManager.Notes> generateChord(GridManager.Notes note)
    {
        List <GridManager.Notes> chord = new List <GridManager.Notes>();

        chord.Add(note);
        if (major)
        {
            chord.Add((GridManager.Notes)(((int)note) + 4));
            chord.Add((GridManager.Notes)(((int)note) + 7));
        }
        else
        {
            chord.Add((GridManager.Notes)(((int)note) + 3));
            chord.Add((GridManager.Notes)(((int)note) + 7));
        }
        return(chord);
    }
    //given an input, harmonize each note at the keys divisble by keysToHarmonise, add those harmonisations to harmonizedInput, and return that.
    private Dictionary <int, List <GridManager.Notes> > harmonizeInput(Dictionary <int, List <GridManager.Notes> > input, Dictionary <int, List <GridManager.Notes> > harmonizedInput)
    {
        int keysToHarmonise = 4;

        wipeDict(harmonizedInput);
        int[] upperOrLower = new int[2] {
            2, -2
        };
        Dictionary <int, List <GridManager.Notes> > notesToAdd = new Dictionary <int, List <GridManager.Notes> >();

        foreach (KeyValuePair <int, List <GridManager.Notes> > pair in input)
        {
            notesToAdd.Add(pair.Key, new List <GridManager.Notes>());
            foreach (GridManager.Notes note in pair.Value)
            {
                if (pair.Key % keysToHarmonise == 0)
                {
                    try{
                        int indexInScale = availableNotes.IndexOf(note);

                        int r = random.Next(upperOrLower.Length);
                        GridManager.Notes newHarmonizedNote = getNoteFromInt(indexInScale + upperOrLower[r]);

                        notesToAdd[pair.Key].Add(newHarmonizedNote);
                    }catch (System.Exception) {
                        Debug.Log("ERROR: Note does not index in available notes!");
                        break;
                        throw;
                    }
                }
            }
        }

        foreach (KeyValuePair <int, List <GridManager.Notes> > pair in notesToAdd)
        {
            foreach (GridManager.Notes note in pair.Value)
            {
                harmonizedInput[pair.Key].Add(note);
            }
        }
        return(harmonizedInput);
    }
 public ChainLink(GridManager.Notes note)
 {
     mainNote = note;
 }
 //given a note, play it on Super Collider.
 private void playNote(GridManager.Notes note)
 {
     print(note);
     VertexManager.contactSC(note, 0.5f, 0.5f, "VoiceA");
 }
Ejemplo n.º 12
0
 public void setLastVertexNote(GridManager.Notes newLastVertexNote)
 {
     lastVertexNote = newLastVertexNote;
 }
Ejemplo n.º 13
0
 public void setVertexNote(GridManager.Notes newVertexNote)
 {
     vertexNote = newVertexNote;
 }