Exemple #1
0
    /*************************************************************************//**
    * @}
    * @defgroup SC_NDiaPubFunc Public Functions
    * @ingroup DocSC_NDia
    * These are functions that allow for interaction between the SC_NoteDialog and other classes.
    * @{
    *****************************************************************************/

    /**
     * @brief Loads a @link Music::CombinedNote note@endlink into the SC_NoteDialog
     * @param[in] aNote The @link Music::CombinedNote note@endlink to load.
     */
    public void LoadNoteIntoDialog(Music.CombinedNote aNote)
    {
        Music.MelodyNote     melody     = aNote.MusicalNote;
        Music.PercussionNote percussion = aNote.Drums;

        // Add display panels.
        if (melody.NumPitches > 0)
        {
            // Add each pitch in the note.
            int index = 0;
            foreach (Music.PITCH pitch in melody.Pitches)
            {
                GameObject clone = Instantiate(Resources.Load <GameObject>(PDDP_PREFAB_PATH));
                clone.transform.SetParent(mMelodyDisplay);

                SC_PitchDrumDisplayPanel panel = clone.AddComponent <SC_PitchDrumDisplayPanel>();
                panel.InitializeAsPitchDisplay(melody.Pitches[index], melody.Lengths[index], melody.Velocities[index]);
                panel.SetParentContainer(this);
                mPitches.Add(panel);
                index++;
                clone = null;
            }
        }

        // Add each drum in the note.
        if (percussion.NumHits > 0)
        {
            int index = 0;
            foreach (Music.DRUM drum in percussion.Hits)
            {
                GameObject clone = Instantiate(Resources.Load <GameObject>(PDDP_PREFAB_PATH));
                clone.transform.SetParent(mPercussionDisplay);

                SC_PitchDrumDisplayPanel panel = clone.AddComponent <SC_PitchDrumDisplayPanel>();
                panel.InitializeAsDrumDisplay(percussion.Hits[index], percussion.Velocities[index]);
                panel.SetParentContainer(this);
                mDrums.Add(panel);
                index++;
                clone = null;
            }
        }

        // Set the offset panel.
        mOffsetPanel.SetSelected(aNote.OffsetFromPrevNote);

        // Set the Done button
        UpdateDoneButton();
    }
Exemple #2
0
    /**
     * @brief Handles the done button being clicked.
     */
    private void OnDoneButtonClicked()
    {
        // Set up the pitches.
        int numPitches = mPitches.Count;

        Music.PITCH[]      pitches         = null;
        int[]              pitchVelocities = null;
        Music.NoteLength[] lengths         = null;

        // If there are pitches, then get them from the panels.
        if (numPitches != 0)
        {
            // Get all of the pitches, velocities, and lengths.
            pitches         = new Music.PITCH[numPitches];
            pitchVelocities = new int[numPitches];
            lengths         = new Music.NoteLength[numPitches];
            int index = 0;
            foreach (SC_PitchDrumDisplayPanel pitch in mPitches)
            {
                pitches[index]         = pitch.GetPitch();
                pitchVelocities[index] = pitch.GetNoteVelocity();
                lengths[index]         = pitch.GetLengthOfPitch();
                index++;
            }
        }

        // Create the melody note.
        Music.MelodyNote melody = new Music.MelodyNote(pitchVelocities, lengths, pitches);

        // Set up the drums.
        int numDrums = mDrums.Count;

        Music.DRUM[] drums          = null;
        int[]        drumVelocities = null;

        // If there are drums, then get them from the panels.
        if (numDrums != 0)
        {
            // Get all of the drums and their velocities.
            drums          = new Music.DRUM[numDrums];
            drumVelocities = new int[numDrums];
            int index = 0;
            foreach (SC_PitchDrumDisplayPanel drum in mDrums)
            {
                drums[index]          = drum.GetDrum();
                drumVelocities[index] = drum.GetNoteVelocity();
                index++;
            }
        }

        // Create the percussion note.
        Music.PercussionNote percussion = new Music.PercussionNote(drumVelocities, drums);

        // Get the offset of the note.
        Music.NoteLength offset = mOffsetPanel.GetSelected();

        // Create the note.
        Music.CombinedNote note = new Music.CombinedNote(melody, percussion, offset);

        // Invoke the event which signals the dialog being finished.
        NoteDialogFinished.Invoke(note);

        // Self-destruct.
        DestroyImmediate(transform.parent.gameObject, false);
    }
Exemple #3
0
    /*************************************************************************//**
    * @}
    * @defgroup SongPrivFunc Private Functions
    * @ingroup DocSong
    * Functions used internally by the Song.
    * @{
    *****************************************************************************/

    /**
     * @brief Loads a @link DocSongFileFormat Song file@endlink and uses it to set the values for this Song.
     * @param[in] aSongFilePath The path to the Song file.
     * @see @link DocSongFileFormat Song File Format@endlink
     */
    private void LoadSongFromFile(string aSongFilePath)
    {
        // Create some variables for parsing the file.
        Music.PITCH[]             curNotePitches = null;
        Music.DRUM[]              curNoteDrums   = null;
        Music.NoteLength[]        curNoteLengths = null;
        List <Music.CombinedNote> notesInFile    = new List <Music.CombinedNote>();
        int splitLineIndex = 0;

        int[] curNoteMelodyVelocities = null;
        int[] curNoteDrumVelocities   = null;

        // Open the file stream.
        StreamReader parser = new StreamReader(aSongFilePath);

        // Get the name of the Song
        string curLine = parser.ReadLine();

        mName = curLine;

        // Get the Song type.
        curLine = parser.ReadLine();
        string[] splitLine = curLine.Split(';');
        mType = (SongType)int.Parse(splitLine[0]);

        // Get the default BPM
        mBPM = int.Parse(splitLine[1]);

        // Get the time signature
        mTimeSignature.BeatsPerMeasure = int.Parse(splitLine[2]);
        mTimeSignature.BaseBeat        = (Music.NOTE_LENGTH_BASE) int.Parse(splitLine[3]);

        // Get the notes of the Song.
        curLine = parser.ReadLine();
        while (curLine != null)
        {
            // Get the line and reset the split line index.
            splitLine      = curLine.Split(';');
            splitLineIndex = 0;

            // Get the pitches for the note if needed.
            if (mType != SongType.DrumLoop)
            {
                curNotePitches = ParsePitches(splitLine[splitLineIndex]);
            }

            // Get the drums for the note if needed.
            if (mType != SongType.Melody)
            {
                curNoteDrums = ParseDrums(splitLine[splitLineIndex]);
            }

            // Go to the next section of the line.
            splitLineIndex++;

            // If needed, get the melody note lengths.
            if (mType != SongType.DrumLoop)
            {
                // Reset the note length array.
                curNoteLengths = null;

                // See if there are lengths for the note.
                if (splitLine[splitLineIndex] != "null")
                {
                    // Get the lengths
                    string[] lengths = splitLine[splitLineIndex].Split(',');
                    curNoteLengths = new Music.NoteLength[lengths.Length];
                    for (int i = 0; i < curNoteLengths.Length; i++)
                    {
                        // Use the constructor for the NoteLength struct that takes a string parameter.
                        curNoteLengths[i] = new Music.NoteLength(lengths[i]);
                    }
                    lengths = null;
                }

                // Go to the next section.
                splitLineIndex++;
            }

            // Get the offset from the previous note.
            Music.NoteLength offset = new Music.NoteLength(splitLine[splitLineIndex]);
            splitLineIndex++;

            // Get the velocities of the note.
            if (mType == SongType.CombinedMelodyAndPercussion)
            {
                // If this Song is a combined Song, then get velocities for both drums and melody.
                string[] allVelocitiesString = splitLine[splitLineIndex].Split('|');

                // Get the melody velocities if there are any for this note.
                if (allVelocitiesString[0] != "null")
                {
                    string[] melodyVelocitiesString = allVelocitiesString[0].Split(',');
                    curNoteMelodyVelocities = new int[melodyVelocitiesString.Length];
                    for (int i = 0; i < curNoteMelodyVelocities.Length; i++)
                    {
                        curNoteMelodyVelocities[i] = int.Parse(melodyVelocitiesString[i]);
                    }
                    melodyVelocitiesString = null;
                }

                // Get the drum velocities if there are any for this note.
                if (allVelocitiesString[1] != "null")
                {
                    string[] drumVelocitiesString = allVelocitiesString[1].Split(',');
                    curNoteDrumVelocities = new int[drumVelocitiesString.Length];
                    for (int i = 0; i < curNoteDrumVelocities.Length; i++)
                    {
                        curNoteDrumVelocities[i] = int.Parse(drumVelocitiesString[i]);
                    }
                    drumVelocitiesString = null;
                }
            }
            // If this Song is a melody, then get the melody velocities for the note.
            else if (mType == SongType.Melody)
            {
                string[] melodyVelocitiesString = splitLine[splitLineIndex].Split(',');
                curNoteMelodyVelocities = new int[melodyVelocitiesString.Length];
                for (int i = 0; i < curNoteMelodyVelocities.Length; i++)
                {
                    curNoteMelodyVelocities[i] = int.Parse(melodyVelocitiesString[i]);
                }
                melodyVelocitiesString = null;
            }
            // If the Song is a drum loop, then get the drum velocities for the note.
            else
            {
                string[] drumVelocitiesString = splitLine[splitLineIndex].Split(',');
                curNoteDrumVelocities = new int[drumVelocitiesString.Length];
                for (int i = 0; i < curNoteDrumVelocities.Length; i++)
                {
                    curNoteDrumVelocities[i] = int.Parse(drumVelocitiesString[i]);
                }
                drumVelocitiesString = null;
            }

            // Add the note to the temp list.
            Music.MelodyNote     melody     = new Music.MelodyNote(curNoteMelodyVelocities, curNoteLengths, curNotePitches);
            Music.PercussionNote percussion = new Music.PercussionNote(curNoteDrumVelocities, curNoteDrums);
            notesInFile.Add(new Music.CombinedNote(melody, percussion, offset));

            curNoteMelodyVelocities = null;
            curNoteDrumVelocities   = null;
            curNoteLengths          = null;

            // Get the next line
            curLine = parser.ReadLine();
        }
        parser.Close();

        // Put the notes from the file into the Song.
        foreach (Music.CombinedNote note in notesInFile)
        {
            AddNote(note);
        }

        // Clean up.
        notesInFile.Clear();
        notesInFile = null;
        Resources.UnloadUnusedAssets();
    }