示例#1
0
    public void PlayLoop(double[][] loopBeats, AudioSource[] originalAudioSources, int loopNumber)
    {
        RemoveLoop(loopNumber);

        Loop loopToAdd = new Loop();

        loopToAdd.noteBeats = new List <List <double> >();
        for (int i = 0; i < loopBeats.Length; i++)
        {
            List <double> loopBeatList = new List <double>(loopBeats[i]);
            loopToAdd.noteBeats.Add(loopBeatList);
        }

        loops[loopNumber] = loopToAdd;
        Loop fixedLoop = GetLoopWithRedundantNotesRemoved(loopToAdd);

        for (int trackNumber = 0; trackNumber < fixedLoop.noteBeats.Count; trackNumber++)
        {
            if (fixedLoop.noteBeats[trackNumber].Count > 0)
            {
                // Clean up old beats and loop sources
                // TODO: Recycle loop sources when possible


                // Setup next note time
                TrackLoopInfo track = AddNoteBeatsToTrack(fixedLoop.noteBeats[trackNumber].ToArray(), tracks [trackNumber], originalAudioSources [trackNumber]);
                track.currentNoteIndex = 0;
                double startOfMeasure = SongController.GetNextStartOfMeasure();
                track.nextNoteTime   = startOfMeasure + track.noteBeats [0] / SongController.GetBPM() * 60.0;
                tracks [trackNumber] = track;
            }
        }
    }
示例#2
0
    TrackLoopInfo RemoveNoteBeatsFromTrack(TrackLoopInfo track, List <double> noteBeats)
    {
        // Remove note beats
        // TODO: Efficiency improvements
        for (int i = 0; i < noteBeats.Count; i++)
        {
            for (int trackNoteBeatIndex = 0; trackNoteBeatIndex < track.noteBeats.Count; trackNoteBeatIndex++)
            {
                if (Mathf.Approximately((float)track.noteBeats[trackNoteBeatIndex], (float)noteBeats[i]))
                {
                    track.noteBeats.RemoveAt(trackNoteBeatIndex);
                    Object.Destroy(track.audioSources[trackNoteBeatIndex]);
                    track.audioSources.RemoveAt(trackNoteBeatIndex);
                    break;
                }
            }
        }

        // Recalculate next note stuff for track
        if (track.noteBeats.Count > 0)
        {
            track.currentNoteIndex = 0;
            double startOfMeasure = SongController.GetNextStartOfMeasure();
            track.nextNoteTime = startOfMeasure + track.noteBeats[0] / SongController.GetBPM() * 60.0;
        }

        return(track);
    }
示例#3
0
 public void RecordNoteAtTime(double noteDSPTime, int instrumentNumber)
 {
     if (isRecording)
     {
         double noteBeat = (noteDSPTime - startRecordingDSPTime) / 60 * SongController.GetBPM();
         if (noteBeat >= 0 && noteBeat < 4)
         {
             double[] newNotes = new double[recordedNotes[instrumentNumber].Length + 1];
             for (int i = 0; i < recordedNotes[instrumentNumber].Length; i++)
             {
                 newNotes[i] = recordedNotes[instrumentNumber][i];
             }
             newNotes[newNotes.Length - 1]   = noteBeat;
             recordedNotes[instrumentNumber] = newNotes;
         }
     }
 }
示例#4
0
    TrackLoopInfo ScheduleNextNoteForTrack(TrackLoopInfo track)
    {
        // Schedule the note to play
        track.audioSources[track.currentNoteIndex].PlayScheduled(track.nextNoteTime);

        // When the next note plays
        track.currentNoteIndex++;
        if (track.currentNoteIndex >= track.noteBeats.Count)
        {
            track.currentNoteIndex = 0;
            track.nextNoteTime    += (4 - track.noteBeats[track.noteBeats.Count - 1] + track.noteBeats[0]) / SongController.GetBPM() * 60;
        }
        else
        {
            track.nextNoteTime += (track.noteBeats[track.currentNoteIndex] - track.noteBeats[track.currentNoteIndex - 1]) / SongController.GetBPM() * 60;
        }

        return(track);
    }