/* / PRIVATE METHODS */ /* PUBLIC METHODS */ public void ConstructWAV() /* Package the music sheet and store it as a WAV file */ { /* Local Variables */ OffsetFrequencyDurationTableListMap positionFrequencyDurationTable; /* Maps duration offsets (in seconds) to a list of musical sheets that should begin playing at that offset */ WAVFile wavFile; /* WAV file object to convert frequency and duration data to a WAV binary */ double offset; /* Buffer for the current offset (in seconds) */ int i; /* Increment variable */ /* Local Variables */ /* Create frequency and duration tables from the main sheet */ ConstructFreqAndDurationTables(noteSheet.Sheet, out double[][] frequencyTable, out double[] durationTable); /* Create a list for the first offset (where the main sheet will be placed) and add that buffer to the main map */ positionFrequencyDurationTable = new OffsetFrequencyDurationTableListMap { { 0.0, new FrequencyDurationTableList { new FrequencyDurationTable(frequencyTable, durationTable) } } }; foreach (KeyValuePair <int, SheetSet> positionSheetSetPair in noteSheet.Layers) { /* Convert a note position to an offset by summing the note lengths before it */ offset = 0.0; for (i = 0; i < positionSheetSetPair.Key; ++i) { offset += noteSheet.Sheet[i][0].length; } foreach (Sheet layerSheet in positionSheetSetPair.Value) { /* Create frequency and duration tables from this layer */ ConstructFreqAndDurationTables(layerSheet, out double[][] layerFrequencyTable, out double[] layerDurationTable); /* If there is already a table at this duration, add this table to the map */ if (positionFrequencyDurationTable.ContainsKey(offset)) { positionFrequencyDurationTable[offset].Add(new FrequencyDurationTable(layerFrequencyTable, layerDurationTable)); } /* If there is no table at this duration, create a new table list and add that to the map */ else { positionFrequencyDurationTable.Add ( offset, new FrequencyDurationTableList { new FrequencyDurationTable(layerFrequencyTable, layerDurationTable) } ); } } } /* Write WAV file */ wavFile = new WAVFile(positionFrequencyDurationTable, filepath, Path.ChangeExtension(filename, WAVFile.WAV_FILE_EXT)); wavFile.WriteWAVFile(); }