private void setPattern ( int pattNum , ModfileInputStream inputStream ) throws IOException { int row = 0 ; PatternRow currentRow = getPatternContainer ( ) . getPatternRow ( pattNum , row ) ; int count = inputStream . readIntelWord ( ) - 2 ; // this read byte also counts while ( count >= 0 ) { int packByte = inputStream . readByteAsInt ( ) ; count -- ; if ( packByte == 0 ) { row ++ ; if ( row >= 64 ) break ; // Maximum. But do we have to break?! Donnow... else currentRow = getPatternContainer ( ) . getPatternRow ( pattNum , row ) ; } else { int channel = packByte & 31 ; // there is the channel channel = channelMap [ channel ] ; int period = 0 ; int noteIndex = 0 ; int instrument = 0 ; int volume = - 1 ; int effekt = 0 ; int effektOp = 0 ; if ( ( packByte & 32 ) != 0 ) // Note and Sample follow { int ton = inputStream . readByteAsInt ( ) ; count -- ; if ( ton == 254 ) { noteIndex = period = Helpers . NOTE_CUT ; // This is our NoteCutValue! } else { // calculate the new note noteIndex = ( ( ton >> 4 ) + 1 ) * 12 + ( ton & 0xF ) ; // fit to it octacves if ( noteIndex >= Helpers . noteValues . length ) { period = 0 ; noteIndex = 0 ; } else { period = Helpers . noteValues [ noteIndex ] ; noteIndex ++ ; } } instrument = inputStream . readByteAsInt ( ) ; count -- ; } if ( ( packByte & 64 ) != 0 ) // volume following { volume = inputStream . readByteAsInt ( ) ; count -- ; } if ( ( packByte & 128 ) != 0 ) // Effekts! { effekt = inputStream . readByteAsInt ( ) ; count -- ; effektOp = inputStream . readByteAsInt ( ) ; count -- ; } if ( channel != - 1 ) { PatternElement currentElement = currentRow . getPatternElement ( channel ) ; currentElement . setNoteIndex ( noteIndex ) ; currentElement . setPeriod ( period ) ; currentElement . setInstrument ( instrument ) ; if ( volume != - 1 ) { currentElement . setVolumeEffekt ( 1 ) ; currentElement . setVolumeEffektOp ( volume ) ; } currentElement . setEffekt ( effekt ) ; currentElement . setEffektOp ( effektOp ) ; } } } }
Set a Pattern by interpreting