Ejemplo n.º 1
0
    void FixedUpdate()
    {
        locationBarOffset = m_settings.locationBarOffset;
        int tactPosWithOffset    = m_tokenposition.GetTactPosition(this.m_locationBar.position - locationBarOffset);
        int startBarTactPosition = m_tokenposition.GetTactPosition(GameObject.Find(m_settings.startBarLoop).transform.position);
        int endBarTactPosition   = m_tokenposition.GetTactPosition(GameObject.Find(m_settings.endtBarLoop).transform.position);

        // TODO: if beat
        Debug.Log(GameObject.Find(m_settings.startBarLoop).transform.position.x + "," + GameObject.Find(m_settings.locationBarName).transform.position.x);
        Debug.Log("Is Appr?: " + Mathf.Approximately(GameObject.Find(m_settings.startBarLoop).transform.position.x, GameObject.Find(m_settings.locationBarName).transform.position.x));
        if (tactPosWithOffset >= startBarTactPosition && (tactPosWithOffset != oldTactPos || (endBarTactPosition - startBarTactPosition == 1 && locationBarIsNearStartBar(0.07f))))
        {
            lastSentNote = tactPosWithOffset;
            int nextBeat = tactPosWithOffset < (m_settings.beats - 1) ? tactPosWithOffset + 1 : 0;

            //reads active markers dependend on enabled chords or not
            if (!enableChords)
            {
                activeMarkers = m_lastComeLastServe.GetActiveMarkers(Color.white);
                GameObject[] arrayToSend = new GameObject[3];

                //calculates string on guitar which will be played and sets the tune to be played on the position of the array assigned to the string
                arrayToSend[m_tokenposition.GetNote(activeMarkers[tactPosWithOffset].transform.position) / tunesPerString] = activeMarkers[tactPosWithOffset];
                if (tactPosWithOffset > 0)
                {
                    lastSentIDs[0] = activeMarkers[tactPosWithOffset - 1] != null ? activeMarkers[tactPosWithOffset - 1].GetComponent <FiducialController>().MarkerID : -1;
                }
                else
                {
                    lastSentIDs[0] = -1;
                }
                this.SendNote(arrayToSend, new bool[] { activeMarkers[nextBeat] == null }, lastSentIDs, tactPosWithOffset);
            }
            else
            {
                activeRedNotes   = m_lastComeLastServe.GetActiveMarkers(m_settings.red);
                activeGreenNotes = m_lastComeLastServe.GetActiveMarkers(m_settings.green);
                activeBlueNotes  = m_lastComeLastServe.GetActiveMarkers(m_settings.blue);

                if (tactPosWithOffset > m_tokenposition.GetTactPosition(GameObject.Find(m_settings.startBarLoop).transform.position)) // TODO don'T use > 0 use > min tact
                {
                    lastSentIDs[0] = activeRedNotes[tactPosWithOffset - 1] != null ? activeRedNotes[tactPosWithOffset - 1].GetComponent <FiducialController>().MarkerID : -1;
                    lastSentIDs[1] = activeGreenNotes[tactPosWithOffset - 1] != null ? activeGreenNotes[tactPosWithOffset - 1].GetComponent <FiducialController>().MarkerID : -1;
                    lastSentIDs[2] = activeBlueNotes[tactPosWithOffset - 1] != null ? activeBlueNotes[tactPosWithOffset - 1].GetComponent <FiducialController>().MarkerID : -1;
                }
                else
                {
                    lastSentIDs[0] = -1;
                    lastSentIDs[1] = -1;
                    lastSentIDs[2] = -1;
                }
                this.SendNote(new GameObject[] { activeRedNotes[tactPosWithOffset], activeGreenNotes[tactPosWithOffset], activeBlueNotes[tactPosWithOffset] }, new bool[] { activeRedNotes[nextBeat] == null, activeGreenNotes[nextBeat] == null, activeBlueNotes[nextBeat] == null }, lastSentIDs, tactPosWithOffset);
            }
            oldTactPos = tactPosWithOffset;
        }
    }
Ejemplo n.º 2
0
    public float CalculateYPosition(Vector3 pos, FiducialController fiducialController, int currentBeat)
    {
        //only does something, if the marker lays still
        if (fiducialController.MovementDirection == Vector2.zero)
        {
            //if marker is not in the recognised jokerMarker dictionary - set y Position
            if (oldPosition.x != pos.x)
            {
                Debug.Log("Joker Marker " + fiducialController.MarkerID + " has been set.");
                realOldYPosition = pos.y;

                //checks which pentatonic tunes are not occupied
                List <GameObject[]> allActiveMarkers          = m_lastComeLastServe.GetAllActiveMarkers();
                List <int>          freePentatonicTuneHeights = new List <int>();

                int  i = 0;
                bool isInRangeOfString = false;
                //Gets current tune of marker and thereby knows on which string it must calc free tune
                if (m_lastComeLastServe.enableChords)
                {
                    i = m_tokenPosition.GetNote(Camera.main.ScreenToWorldPoint(pos));
                    i = i < m_settings.tunesPerString ? 0 : (i < (m_settings.tunesPerString * 2) ? 1 : 2);
                }

                for (int j = 0; j < pentatonicTunes.Length; j++)
                {
                    //if chords are not enabled, jump between strings
                    if (!m_lastComeLastServe.enableChords && (i + 1) * m_settings.tunesPerString < pentatonicTunes[j])
                    {
                        i++;
                    }
                    //else if chords are enabled, check if current pentatonic tune is in range of current string
                    else if (m_lastComeLastServe.enableChords && i * m_settings.tunesPerString < pentatonicTunes[j] && pentatonicTunes[j] < (i + 1) * m_settings.tunesPerString)
                    {
                        isInRangeOfString = true;
                    }
                    else
                    {
                        isInRangeOfString = false;
                    }

                    if ((m_lastComeLastServe.enableChords ? isInRangeOfString : 1 == 1) && (allActiveMarkers[i][currentBeat] == null || m_tokenPosition.GetNote(allActiveMarkers[i][currentBeat].transform.position) + 1 != pentatonicTunes[j]))
                    {
                        freePentatonicTuneHeights.Add(pentatonicTunes[j]);
                    }
                }
                //Gets random pentatonic tune and calculates y position based on said tune
                pos.y       = heightOffSet_bottom + freePentatonicTuneHeights[(int)Random.Range(0, freePentatonicTuneHeights.Count)] * cellHeightInPx - cellHeightInPx / 2;
                oldPosition = pos;

                return(pos.y);
            }
            else
            {
                return(oldPosition.y);
            }
        }
        //marker is moving
        return(pos.y);
    }
    public void CheckColor()
    {
        note = m_tokenPosition.GetNote(this.transform.position);

        if (note < tunesPerString)
        {
            rend.color = blue;
        }
        else if (note < tunesPerString * 2)
        {
            rend.color = green;
        }
        else
        {
            rend.color = red;
        }
    }
Ejemplo n.º 4
0
    //Gets beat from each marker of the passed list and checks if this marker is the latest marker on said beat
    private void RunThroughMarkerListAndUpdateActiveMarkers(List <GameObject> markerList, GameObject[] activeMarkersArray, Color color)
    {
        foreach (GameObject marker in markerList)
        {
            FiducialController m_fiducial = marker.GetComponent <FiducialController>();

            if (m_fiducial.IsSnapped())
            {
                //gets beat on which the the marker lies on
                int beat = m_tokenPosition.GetTactPosition(marker.transform.position);
                //gets tune on which the marker lies on and checks if the tune has changed. If so --> log message
                int tune = m_tokenPosition.GetNote(marker.transform.position);
                if ((tune + 1) != currentTunes[m_fiducial.MarkerID])
                {
                    //only sends Log message if it's not the first tune change
                    if (currentTunes[m_fiducial.MarkerID] != 0)
                    {
                        Debug.Log("Marker " + m_fiducial.MarkerID + " changed tune from " + (currentTunes[m_fiducial.MarkerID] + 1) + " to " + (tune + 1) + ".");
                    }
                    currentTunes[m_fiducial.MarkerID] = tune + 1;
                }

                //checks if this marker isn't already the one in the activeMarker list
                if (activeMarkersArray[beat] != marker)
                {
                    int width = (int)(m_settings.GetMarkerWidthMultiplier(m_fiducial.MarkerID) * 2);

                    //if beat position is empty or if position is not empty, current marker hast snapped before marker on beat
                    if (activeMarkersArray[beat] == null || (activeMarkersArray[beat].GetComponent <FiducialController>().GetLastTimeSnapped() < m_fiducial.GetLastTimeSnapped()))
                    {
                        //if the marker is wider/longer than one beat
                        if (width > 1)                                                                                                                                                                                              //mind 1/2
                        {
                            beat = beat == 0 ? 1 : beat;                                                                                                                                                                            // TODO: beat can't be at 0 for width > 1
                            //checks if second beat of the marker is not ok, if so: break
                            if (beat - 1 > m_settings.beats || (activeMarkersArray[beat - 1] != null && (activeMarkersArray[beat - 1].GetComponent <FiducialController>().GetLastTimeSnapped() > m_fiducial.GetLastTimeSnapped()))) //1/2
                            {
                                break;
                            }
                            else
                            {
                                if (width > 2)                                                                                                                                                                               // mind 3/4
                                {
                                    beat = beat == 0 ? 2 : beat;                                                                                                                                                             // TODO: beat can't be at 0 for width > 1
                                    //checks if third beat of the marker is not ok, if so: break
                                    if (beat + 1 < 0 || (activeMarkersArray[beat + 1] != null && (activeMarkersArray[beat + 1].GetComponent <FiducialController>().GetLastTimeSnapped() > m_fiducial.GetLastTimeSnapped()))) //3/4
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        if (width > 3)                                                                                                                                                                                              // 4/4
                                        {
                                            beat = beat == 0 ? 3 : beat;                                                                                                                                                                            // TODO: beat can't be at 0 for width > 3
                                            //checks if fourth beat of the marker is not ok, if so: break
                                            if (beat - 2 > m_settings.beats || (activeMarkersArray[beat - 2] != null && (activeMarkersArray[beat - 2].GetComponent <FiducialController>().GetLastTimeSnapped() > m_fiducial.GetLastTimeSnapped()))) //4/4
                                            {
                                                break;
                                            }
                                            this.ActivateMarkerOnBeatWithColor(marker, activeMarkersArray, beat - 2, color); //4/4
                                        }
                                        this.ActivateMarkerOnBeatWithColor(marker, activeMarkersArray, beat + 1, color);     //3/4
                                    }
                                }
                                this.ActivateMarkerOnBeatWithColor(marker, activeMarkersArray, beat - 1, color); //1/2
                            }
                        }
                        this.ActivateMarkerOnBeatWithColor(marker, activeMarkersArray, beat, color); //1/4
                        Debug.Log("Marker " + m_fiducial.MarkerID + " got activated on position " + (width > 3 ? beat - 1 : (width > 1 ? beat : beat + 1)) + " on tune " + (m_tokenPosition.GetNote(marker.transform.position) + 1) + " for " + width + " beat/s.");
                    }
                }
            }
        }
    }