예제 #1
0
        public void writeMetaData(int _id, int _octave, int _bpm, int _buf)
        {
            int[] bpm = convertBaseBig(_bpm);
            int[] id  = convertBaseSmall(_id);
            int[] buf = convertBaseSmall(_buf);

            if (dNotes.Count < 2)
            {
                /*
                 * // First part of the meta data
                 * Tone part1 = new Tone(0, 0, 8, _octave, id[0], id[1], bpm[0]);
                 *
                 * // Second part
                 * // passing -2 for the octave and the delay will prevent that middle part from being rendered
                 * Tone part2 = new Tone(1, buf[0], bpm[1], buf[1], -2, -2, bpm[2]);
                 */


                // First part of the meta data
                Tone part1 = new Tone(0, 0, 8, id[1], 0, 8, id[0]);

                // Second part
                Tone part2 = new Tone(0, _octave, bpm[0], buf[1], bpm[1], buf[0], bpm[2]);

                // TODO: Fix the -2 issue
                // passing -2 for the octave and the delay will prevent that middle part from being rendered



                dNotes.Add(part1);
                dNotes.Add(part2);

                var newChartData1 = part1.returnSegments();
                for (int i = 0; i < newChartData1.Count(); i++)
                {
                    for (int c = 0; c < newChartData1[i].Count(); c++)
                    {
                        var newdata       = newChartData1[i][c];
                        var SelectedTrack = ChartRow[i + (2 * CurrentTrack)];
                        SelectedTrack.Insert(SelectedTrack.Count, newdata);
                    }
                }

                var newChartData2 = part2.returnSegments();
                for (int i = 0; i < newChartData2.Count(); i++)
                {
                    for (int c = 0; c < newChartData2[i].Count(); c++)
                    {
                        var newdata       = newChartData2[i][c];
                        var SelectedTrack = ChartRow[i + (2 * CurrentTrack)];
                        SelectedTrack.Insert(SelectedTrack.Count, newdata);
                    }
                }

                ToneCounter = returnElementCount();

                updatePlaceholders();
            }
            else
            {
                // First part of the meta data
                Tone part1 = new Tone(0, 0, 8, id[1], 0, 8, id[0]);

                // Second part
                Tone part2 = new Tone(0, _octave, bpm[0], buf[1], bpm[1], buf[0], bpm[2]);

                var newChartData1 = part1.returnSegments();
                var newChartData2 = part2.returnSegments();

                // Locate the meta data at the beginning of the song
                int startId       = 0;
                int selectedTrack = 0;

                // Remove 5 the first 5 elements at the beginning of the track
                for (int i = 0; i < MetadataSize; i++)
                {
                    for (int c = 0; c < newChartData1.Count(); c++)
                    {
                        ChartRow[c + (2 * selectedTrack)].RemoveAt(startId);
                    }
                }

                // Insert part 1 of the meta data
                for (int i = 0; i < newChartData1.Count(); i++)
                {
                    for (int c = 0; c < newChartData1[i].Count(); c++)
                    {
                        var newdata       = newChartData1[i][c];
                        var SelectedTrack = ChartRow[i + (2 * selectedTrack)];
                        SelectedTrack.Insert(startId + c, newdata);
                    }
                }

                // Insert part 2 of the meta data after the first one
                for (int i = 0; i < newChartData2.Count(); i++)
                {
                    for (int c = 0; c < newChartData2[i].Count(); c++)
                    {
                        var newdata       = newChartData2[i][c];
                        var SelectedTrack = ChartRow[i + (2 * selectedTrack)];
                        SelectedTrack.Insert(startId + newChartData1[i].Count() + c, newdata);
                    }
                }

                // TODO: Remove the tonecounter subtraction
                //ToneCounter -= dNotes[_id].NumberOfElements;


                // Replace the meta data in the backend dictionary
                dNotes.RemoveAt(1);
                dNotes.RemoveAt(0);
                dNotes.Insert(0, part1);
                dNotes.Insert(1, part2);

                ToneCounter = returnElementCount();

                updatePlaceholders();
            }

            hasMetadata = true;
        }
예제 #2
0
        public int addTone(int _id, int _modifier, int _frequency, int _duration, int _octave, int _delay, int _altmodifier)
        {
            /*
             * // Change pointer to the next track or return -1 if the disk is full
             * if (ToneCounter >= DatafieldsPerTrack)
             * {
             *  if (CurrentTrack >= MaxTrack)
             *  {
             *      return -1;
             *  }
             *  CurrentTrack += 1;
             *  ToneCounter = 1;
             * }
             */
            CurrentTrack = calculateCurrentTrack();
            if (CurrentTrack >= MaxTrack)
            {
                return(-1);
            }

            // Editing an existing note
            if (dNotes.Count > _id)
            {
                Tone _tone        = new Tone(_id, _modifier, _frequency, _duration, _octave, _delay, _altmodifier);
                var  newChartData = _tone.returnSegments();

                // Calcuate the starting id of the tone to change
                int startId = 0;
                for (int i = 0; i < _id; i++)
                {
                    startId += dNotes[i].NumberOfElements;
                }

                /*
                 * //int selectedTrack = 0;
                 * while(startId >= DatafieldsPerTrack)
                 * {
                 *  MessageBox.Show("Elements in row " + (2 * selectedTrack) + ": " + ChartRow[2 * selectedTrack].Count);
                 *  startId -= ChartRow[2 * selectedTrack].Count;
                 *  selectedTrack++;
                 * }
                 */

                int selectedTrack = 0;
                for (int i = startId; i >= DatafieldsPerTrack[2 * selectedTrack]; i -= ChartRow[2 * (selectedTrack - 1)].Count)
                {
                    startId -= ChartRow[2 * selectedTrack].Count;
                    selectedTrack++;
                }

                // Remove elements at the starting position for every element in the tone at that position
                for (int i = 0; i < dNotes[_id].NumberOfElements; i++)
                {
                    for (int c = 0; c < newChartData.Count(); c++)
                    {
                        ChartRow[c + (2 * selectedTrack)].RemoveAt(startId);
                    }
                }

                // Insert the changed tone into the chart
                for (int i = 0; i < newChartData.Count(); i++)
                {
                    for (int c = 0; c < newChartData[i].Count(); c++)
                    {
                        var newdata       = newChartData[i][c];
                        var SelectedTrack = ChartRow[i + (2 * selectedTrack)];
                        SelectedTrack.Insert(startId + c, newdata);
                    }
                }
                // TODO: Remove the tonecounter subtraction
                ToneCounter -= dNotes[_id].NumberOfElements;


                // Replace the note in the backend dictionary
                dNotes.RemoveAt(_id);
                dNotes.Insert(_id, _tone);

                // TODO: Maybe calculate this value instead of relying on adding it up
                // TODO: Write function to calculate it
                // TODO: Maybe remove this as it would lead to problems (Tonecounter = tones in the current track, NOT all tones added together)

                ToneCounter += _tone.NumberOfElements;

                //ToneCounter = returnElementCount();

                updatePlaceholders();
                return(0);
            }
            else
            {
                // Add new tone
                Tone newTone = new Tone(_id, _modifier, _frequency, _duration, _octave, _delay, _altmodifier);

                dNotes.Add(newTone);

                var newChartData = newTone.returnSegments();

                for (int i = 0; i < newChartData.Count(); i++)
                {
                    for (int c = 0; c < newChartData[i].Count(); c++)
                    {
                        var newdata       = newChartData[i][c];
                        var SelectedTrack = ChartRow[i + (2 * CurrentTrack)];
                        SelectedTrack.Insert(SelectedTrack.Count, newdata);
                    }
                }

                ToneCounter += newTone.NumberOfElements;
                //ToneCounter = returnElementCount();

                updatePlaceholders();
                return(1);
            }
        }