1 /**
  2  * This file is part of the Web Enabled Audio and Sound Enhancement Library (aka the Weasel audio library) Copyright 2011 - 2013 Warren Willmey. It is covered by the GNU General Public License version 3 as published by the Free Software Foundation, you should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
  3  */
  4 
  5 if( undefined == window.weasel ) window.weasel = {};
  6 
  7 // ---------------------------------------------------------------------------
  8 /** Object to contain a single Ultimate Soundtracker pattern.
  9  * 
 10  * @constructor
 11  * @param {weasel.UltimateSoundTracker121|weasel.UltimateSoundTracker18|weasel.DOCSoundTracker9|weasel.DOCSoundTracker22|weasel.TJCSoundTracker2|weasel.DefJamSoundTracker3|weasel.SpreadpointSoundTracker23|weasel.SpreadpointSoundTracker25|weasel.NoiseTracker11|weasel.NoiseTracker20|weasel.ProTrackerMK|weasel.FSTModule} oModule = The module containing the patterns.
 12  * @param {int} iPatternNumber = The number of the pattern to extract and construct.
 13  * 
 14  * @author Warren Willmey 2011
 15  */
 16 weasel.Pattern = function( oModule, iPatternNumber )
 17 {
 18 	this.aPatternColumns = new Array( undefined == oModule ? weasel.FormatUltimateSoundTracker121.NumberOfChannels : oModule.getNumberOfChannels() );
 19 
 20 	for( var iColumns = this.aPatternColumns.length, b15Samples = (undefined != oModule && oModule.FormatInstrumentTotal() == 15); --iColumns >= 0; )
 21 		this.aPatternColumns[ iColumns ] = new weasel.PatternColumn( b15Samples );
 22 
 23 	if( null != oModule && oModule.getModuleData().length >= ( oModule.FormatModuleHeaderSize() + (oModule.getPatternSizeInBytes() * (iPatternNumber + 1))) )
 24 		this.__extractPatternDataFromModule( oModule, iPatternNumber );
 25 };
 26 
 27 
 28 // ---------------------------------------------------------------------------
 29 /**
 30  * Populate this Pattern object with the Pattern data in the Ultimate Soundtracker 1.21 module.
 31  * 
 32  * @param {weasel.UltimateSoundTracker121|weasel.UltimateSoundTracker18|weasel.DOCSoundTracker9|weasel.DOCSoundTracker22|weasel.TJCSoundTracker2|weasel.DefJamSoundTracker3|weasel.SpreadpointSoundTracker23|weasel.SpreadpointSoundTracker25|weasel.NoiseTracker11|weasel.NoiseTracker20|weasel.ProTrackerMK|weasel.FSTModule} oModule = The module containing the patterns.
 33  * @param {int} iPatternNumber = The valid pattern number to extract.
 34  * 
 35  * @private
 36  */
 37 weasel.Pattern.prototype.__extractPatternDataFromModule = function( oModule, iPatternNumber )
 38 {
 39 	var aModuleData = oModule.getModuleData();
 40 	var iPatternOffset = oModule.FormatModuleHeaderSize() + ( oModule.getPatternSizeInBytes() * iPatternNumber );
 41 
 42 	for( var iRow = 0, iMaxRows = weasel.FormatUltimateSoundTracker121.NumberOfRowsPerPattern; iRow < iMaxRows ; iRow++ )
 43 	{
 44 
 45 		for( var iColumn = 0, iMaxColumns = this.aPatternColumns.length; iColumn < iMaxColumns; iColumn++ )
 46 		{
 47 			var iCellValue = weasel.Helper.getLong( aModuleData, iPatternOffset );
 48 			iPatternOffset += weasel.FormatUltimateSoundTracker121.BytesPerRowCell;
 49 
 50 			this.aPatternColumns[ iColumn ].getCell( iRow ).setCell( iCellValue );
 51 		}
 52 	}
 53 };
 54 
 55 // ---------------------------------------------------------------------------
 56 /**
 57  * Get a PatternColumn object of this Pattern.
 58  * 
 59  * @param {int} iColumnNumber = The Column Number (starting from zero, e.g. 0-3).
 60  * 
 61  * @return {weasel.PatternColumn} The Pattern Column object for the requested column, or NULL if out of range.
 62  */
 63 weasel.Pattern.prototype.getColumn = function( iColumnNumber )
 64 {
 65 	if( iColumnNumber < 0 || iColumnNumber >= this.aPatternColumns.length )
 66 		return null;
 67 	
 68 	return this.aPatternColumns[ iColumnNumber ];
 69 };
 70