示例#1
0
        void OnPatternChangeUpdateNotesWithNewPatterns()
        {
            //Poll the UI for pattern containers
            var patternToggleContainers = _PatternSetElement.Query <VisualElement>().Class("pattern-list-container").ToList();

            //Each Container is a Visual Element containing a beat pattern with a beat ID
            foreach (VisualElement ve in patternToggleContainers)
            {
                var beatToggles = ve.Query <Toggle>().ToList();

                List <bool> beatToggleValues = new List <bool>();

                //Create the beat list for each note
                foreach (Toggle t in beatToggles)
                {
                    beatToggleValues.Add(t.value);
                }

                BeatPattern beatPattern = new BeatPattern();

                //Any note with this beat ID will play the corresponding pattern
                beatPattern.m_beatID      = System.Convert.ToInt32(ve.name);
                beatPattern.m_beatPattern = beatToggleValues;


                _beatMachine.DispatchPatterns(beatPattern);
            }
        }
示例#2
0
        List <BeatPattern> GetCurrentPatterns(VisualElement elementToQuery, string className)
        {
            List <BeatPattern> patterns = new List <BeatPattern>();
            //Poll the UI for pattern containers
            var toggleContainers = elementToQuery.Query <VisualElement>().Class(className).ToList();

            //each toggle container is a list of booleans, gather and send them to the audio files
            foreach (VisualElement ve in toggleContainers)
            {
                var bools = ve.Query <Toggle>().ToList();
                var note  = ve.Query <ObjectField>().First();

                List <bool> beatValueList = new List <bool>();
                foreach (Toggle t in bools)
                {
                    beatValueList.Add(t.value);
                }

                BeatPattern beatPattern = new BeatPattern();
                beatPattern.m_beatID      = System.Convert.ToInt32(ve.name);
                beatPattern.m_beatPattern = beatValueList;

                patterns.Add(beatPattern);
            }

            return(patterns);
        }
示例#3
0
 //When we change the loop pattern, we notify all of the loops about the new
 //patterns. If they have an ID that matches the pattern, they will add the pattern
 //to their BeatEmitter and use it to play notes as directed, i.e. true = play the note at this point
 //in the pattern
 public void DispatchPatterns(BeatPattern bp)
 {
     if (OnPatternChange != null)
     {
         OnPatternChange(bp);
     }
 }
 public void UpdatePattern(BeatPattern bp)
 {
     if (bp.m_beatID == m_patternID)
     {
         m_pattern = bp.m_beatPattern;
     }
 }
示例#5
0
        void LoadSoundBankAndSetPatternRows(string soundBankName)
        {
            _PatternSetElement.Clear();

            //Rename the soundbank so that a new set of notes are created, but use the old pattern
            _beatMachine.GetSoundBankPrefabsFromName(soundBankName);

            PatternSet newPatternSet = new PatternSet();

            newPatternSet.soundBank   = soundBankName;
            newPatternSet.patterns    = new List <BeatPattern>();
            newPatternSet.tempo       = _beatMachine.m_currentPatternSet.tempo;
            newPatternSet.signatureHi = _beatMachine.m_currentPatternSet.signatureHi;
            newPatternSet.measures    = _beatMachine.m_currentPatternSet.measures;

            //Make a pattern line for each sound
            for (int patternLine = 0; patternLine < _beatMachine.m_soundBankPrefabs.Length; patternLine++)
            {
                BeatPattern bp = new BeatPattern();
                bp.m_beatID = patternLine;
                List <bool> booleans = new List <bool>();

                bool doesOldPatternHaveAPatternAtThisLineNumber = _beatMachine.m_currentPatternSet.patterns.Count > patternLine;
                int  oldPatternLength = 0;
                if (_beatMachine.m_currentPatternSet.patterns.Count > 0)
                {
                    oldPatternLength = _beatMachine.m_currentPatternSet.patterns[0].m_beatPattern.Count;
                }

                VisualElement patternLineVisualElement = new VisualElement();

                _BeatPatternTemplate.CloneTree(patternLineVisualElement);

                //Create the label for this beat pattern
                var label = patternLineVisualElement.Query <Label>().Class("pattern-id").First();
                label.text = patternLine.ToString();

                patternLineVisualElement.AddToClassList("pattern-list-container");

                //Name the pattern with the integer - !important
                patternLineVisualElement.name = patternLine.ToString();

                //Create all of the beat toggles
                for (int b = 0; b < _beatMachine.m_currentPatternSet.measures * _beatMachine.m_currentPatternSet.signatureHi; b++)
                {
                    Toggle toggle = new Toggle();

                    //resuse the current pattern if it is in range of the newly created pattern (number of measures *  signature)
                    if (doesOldPatternHaveAPatternAtThisLineNumber)
                    {
                        if (b < oldPatternLength)
                        {
                            toggle.value = _beatMachine.m_currentPatternSet.patterns[patternLine].m_beatPattern[b];
                        }
                    }

                    toggle.name        = bp.m_beatID.ToString() + "beat" + b.ToString();
                    toggle.viewDataKey = toggle.name;
                    toggle.RegisterCallback <MouseUpEvent>(HandlePatternChanges);

                    if (b > 0 && ((b + 1) % _beatMachine.m_metronome.signatureHi) == 0 && b != bp.m_beatPattern.Count - 1)
                    {
                        toggle.AddToClassList("lastbeat");
                    }
                    else
                    {
                        toggle.AddToClassList("beat");
                    }

                    patternLineVisualElement.Add(toggle);
                    booleans.Add(toggle.value);
                }

                bp.m_beatPattern = booleans;
                newPatternSet.patterns.Add(bp);

                Label l = new Label();
                l.text = _beatMachine.m_soundBankPrefabs[patternLine].name;
                patternLineVisualElement.Add(l);

                _PatternSetElement.Add(patternLineVisualElement);
            }

            OnPatternChangeUpdateNotesWithNewPatterns();

            _beatMachine.m_currentPatternSet = newPatternSet;
            _beatMachine.MakeNoteGameObjects(Vector3.zero);
            _beatMachine.UpdateMenus();
        }