Example #1
0
        /// <summary>
        /// Process the data stored in fTckDataTable, creating the items in fNotes.
        /// </summary>
        private void InitializeSceneItems()
        {
            var auxiliarTable = new GtSceneGuitarNote[6];

            var endPosition = new BeatTick(fTickDataTable.NumberOfBeats, 470);

            for (var pos = new BeatTick(1, 0); pos <= endPosition; pos = pos.AddTicks(10))
            {
                var tickData = fTickDataTable[pos.Beat, pos.Tick];

                SetSceneGuitarNote(ref auxiliarTable, 1, tickData.String1, pos);
                SetSceneGuitarNote(ref auxiliarTable, 2, tickData.String2, pos);
                SetSceneGuitarNote(ref auxiliarTable, 3, tickData.String3, pos);
                SetSceneGuitarNote(ref auxiliarTable, 4, tickData.String4, pos);
                SetSceneGuitarNote(ref auxiliarTable, 5, tickData.String5, pos);
                SetSceneGuitarNote(ref auxiliarTable, 6, tickData.String6, pos);

                if (tickData.IsEndTick)
                {
                    AddNewNoteWhenExists(ref auxiliarTable, 1);
                    AddNewNoteWhenExists(ref auxiliarTable, 2);
                    AddNewNoteWhenExists(ref auxiliarTable, 3);
                    AddNewNoteWhenExists(ref auxiliarTable, 4);
                    AddNewNoteWhenExists(ref auxiliarTable, 5);
                    AddNewNoteWhenExists(ref auxiliarTable, 6);
                }
            }
        }
        virtual protected bool CheckIfNoteIsPlaying(GtSceneGuitarNote pSceneGuitarNote)
        {
            int qtd = PlayingNotes.Where(p =>
                                         (p.Value == pSceneGuitarNote.NoteValue) &&
                                         (p.Number == pSceneGuitarNote.NoteNumber)).Count();

            return(qtd == 1);
        }
Example #3
0
        /// <summary>
        /// Create a new GtSceneGuitarNote when needed, and update the EndPosition.
        /// </summary>
        /// <param name="pAuxiliarTable">Used to keep the references for the recently created GtSceneGuitarNote not ended until now</param>
        /// <param name="pString">String number (1..6)</param>
        /// <param name="pFret">Fret number</param>
        /// <param name="pCurrentPosition">Current position - the note still playing in this position</param>
        private void SetSceneGuitarNote(ref GtSceneGuitarNote[] pAuxiliarTable, int pString, int?pFret, BeatTick pCurrentPosition)
        {
            var position = pCurrentPosition;

            if (pFret != null)
            {
                if (pAuxiliarTable[pString - 1] == null)
                {
                    //if (!tickData.IsStartTick)
                    //    throw ...

                    pAuxiliarTable[pString - 1] = new GtSceneGuitarNote(position, position, pString, (int)pFret);
                }

                pAuxiliarTable[pString - 1].EndPosition = position;
            }
        }
        public bool NoteIsPlaying(GtSceneGuitarNote pSceneGuitarNote)
        {
            //return true; //teste

            var fft = this.AudioListener.FftData;

            //if FFT is not invalid (all zero) update the PlayingNotes list.
            if (fft.Where(p => p != 0).Count() > 0)
            {
                //transform the FFT into a list of musical notes.
                PlayingNotes = this.SpectrumAnalyzer.GetMusicalNotes(fft);
                this.SpectrumAnalyzer.DeleteUnusefulNotes(ref PlayingNotes);
            }

            //query the LastQueriedPlayedNoteslist looking for the pSceneGuitarNote
            if (CheckIfNoteIsPlaying(pSceneGuitarNote))
            {
                MusicalNoteAndTimeStamp playedNote = LastQueriedPlayedNotes.Where(p =>
                                                                                  (p.MusicalNote.Value == pSceneGuitarNote.NoteValue) &&
                                                                                  (p.MusicalNote.Number == pSceneGuitarNote.NoteNumber)).FirstOrDefault();

                if (playedNote != null)
                {
                    playedNote.TimeStamp = this.Factory.Clock.CurrentDateTime;
                }
                else
                {
                    playedNote = new MusicalNoteAndTimeStamp();

                    playedNote.MusicalNote = new MusicalNote(pSceneGuitarNote.NoteValue.ToString() + pSceneGuitarNote.NoteNumber.ToString());
                    playedNote.TimeStamp   = this.Factory.Clock.CurrentDateTime;

                    this.LastQueriedPlayedNotes.Add(playedNote);
                }

                return(true);
            }

            bool noteFound = false;

            for (int i = LastQueriedPlayedNotes.Count - 1; i >= 0; i--)
            {
                var playedNote = LastQueriedPlayedNotes[i];

                //Delete all expired items
                if (playedNote.TimeStamp.AddMilliseconds(DELAY_TIME_FOR_PLAYING_NOTES_RECOGNITION) < this.Factory.Clock.CurrentDateTime)
                {
                    LastQueriedPlayedNotes.RemoveAt(i);
                }
                else
                {
                    //Check if the non expired note is the one we are looking for
                    if ((playedNote.MusicalNote.Value == pSceneGuitarNote.NoteValue) &&
                        (playedNote.MusicalNote.Number == pSceneGuitarNote.NoteNumber))
                    {
                        noteFound = true;
                    }
                }
            }

            return(noteFound);
        }