import { InstrumentalGroup } from "./InstrumentalGroup" ; import { Label } from "./Label" ; import { MusicSheet } from "./MusicSheet" ; import { Voice } from "./VoiceData/Voice" ; import { Staff } from "./VoiceData/Staff" ; import { SubInstrument } from "./SubInstrument" ; import { MidiInstrument } from "./VoiceData/Instructions/ClefInstruction" ; export class Instrument extends InstrumentalGroup { constructor ( id , idString , musicSheet , parent ) { super ( undefined , musicSheet , parent ) ; this . id = id ; this . idString = idString ; this . nameLabel = new Label ( idString ) ; } /** Transposition halftones for this instrument only.
     * You need to call osmd.updateGraphic() before the next render() (assuming this is set after load()).
     */ public Transpose : number = 0 ; public highlight : boolean ; private voices : Voice [ ] = [ ] ; private staves : Staff [ ] = [ ] ; private nameLabel : Label ; private idString : string ; private id : number ; private hasLyrics : boolean = false ; private hasChordSymbols : boolean = false ; private playbackTranspose : number ; private lyricVersesNumbers : number [ ] = [ ] ; private subInstruments : SubInstrument [ ] = [ ] ; private partAbbreviation : string ; public get Voices ( ) : Voice [ ] { return this . voices ; } public get Staves ( ) : Staff [ ] { return this . staves ; } public get NameLabel ( ) : Label { return this . nameLabel ; } public get HasLyrics ( ) : boolean { return this . hasLyrics ; } public set HasLyrics ( value ) { this . hasLyrics = value ; } public get HasChordSymbols ( ) : boolean { return this . hasChordSymbols ; } public set HasChordSymbols ( value ) { this . hasChordSymbols = value ; } public get LyricVersesNumbers ( ) : number [ ] { return this . lyricVersesNumbers ; } public set LyricVersesNumbers ( value ) { this . lyricVersesNumbers = value ; } public get Name ( ) : string { return this . nameLabel . text ; } public set Name ( value ) { this . nameLabel . text = value ; } public get IdString ( ) : string { return this . idString ; } public get Id ( ) : number { return this . id ; } public get MidiInstrumentId ( ) : MidiInstrument { return this . subInstruments [ 0 ] . midiInstrumentID ; } public set MidiInstrumentId ( value ) { this . subInstruments [ 0 ] . midiInstrumentID = value ; } public get Volume ( ) : number { return this . subInstruments [ 0 ] . volume ; } public set Volume ( value ) { for ( let idx = 0 , len = this . subInstruments . length ; idx < len ; ++ idx ) { const subInstrument = this . subInstruments [ idx ] ; subInstrument . volume = value ; } } public get PlaybackTranspose ( ) : number { return this . playbackTranspose ; } public set PlaybackTranspose ( value ) { this . playbackTranspose = value ; } public get SubInstruments ( ) : SubInstrument [ ] { return this . subInstruments ; } public getSubInstrument ( subInstrumentIdString ) { for ( let idx = 0 , len = this . subInstruments . length ; idx < len ; ++ idx ) { const subInstrument = this . subInstruments [ idx ] ; if ( subInstrument . idString === subInstrumentIdString ) { return subInstrument ; } } return undefined ; } public get PartAbbreviation ( ) : string { return this . partAbbreviation ; } public set PartAbbreviation ( value ) { this . partAbbreviation = value ; } public get Visible ( ) : boolean { if ( this . voices . length > 0 ) { return this . Voices [ 0 ] . Visible ; } else { return false ; } } public set Visible ( value ) { for ( let idx = 0 , len = this . Voices . length ; idx < len ; ++ idx ) { const v = this . Voices [ idx ] ; v . Visible = value ; } } public get Audible ( ) : boolean { let result = false ; for ( let idx = 0 , len = this . Voices . length ; idx < len ; ++ idx ) { const v = this . Voices [ idx ] ; result = result || v . Audible ; } return result ; } public set Audible ( value ) { for ( let idx = 0 , len = this . Voices . length ; idx < len ; ++ idx ) { const v = this . Voices [ idx ] ; v . Audible = value ; } for ( let idx = 0 , len = this . staves . length ; idx < len ; ++ idx ) { const staff = this . staves [ idx ] ; staff . audible = value ; } } public get Following ( ) : boolean { let result = false ; for ( let idx = 0 , len = this . Voices . length ; idx < len ; ++ idx ) { const v = this . Voices [ idx ] ; result = result || v . Following ; } return result ; } public set Following ( value ) { for ( let idx = 0 , len = this . Voices . length ; idx < len ; ++ idx ) { const v = this . Voices [ idx ] ; v . Following = value ; } for ( let idx = 0 , len = this . staves . length ; idx < len ; ++ idx ) { const staff = this . staves [ idx ] ; staff . following = value ; } } public SetVoiceAudible ( voiceId , audible ) { for ( let idx = 0 , len = this . Voices . length ; idx < len ; ++ idx ) { const v = this . Voices [ idx ] ; if ( v . VoiceId === voiceId ) { v . Audible = audible ; break ; } } } public SetVoiceFollowing ( voiceId , following ) { for ( let idx = 0 , len = this . Voices . length ; idx < len ; ++ idx ) { const v = this . Voices [ idx ] ; if ( v . VoiceId === voiceId ) { v . Following = following ; break ; } } } public SetStaffAudible ( staffId , audible ) { const staff = this . staves [ staffId - 1 ] ; staff . audible = audible ; if ( audible ) { for ( let idx = 0 , len = staff . Voices . length ; idx < len ; ++ idx ) { const v = staff . Voices [ idx ] ; v . Audible = true ; } } else { for ( let idx = 0 , len = staff . Voices . length ; idx < len ; ++ idx ) { const voice = staff . Voices [ idx ] ; let isAudibleInOtherStaves = false ; for ( let idx2 = 0 , len2 = this . Staves . length ; idx2 < len2 ; ++ idx2 ) { const st = this . Staves [ idx2 ] ; if ( st . Id === staffId || ! st . audible ) { continue ; } for ( let idx3 = 0 , len3 = st . Voices . length ; idx3 < len3 ; ++ idx3 ) { const v = st . Voices [ idx3 ] ; if ( v === voice ) { isAudibleInOtherStaves = true ; } } } if ( ! isAudibleInOtherStaves ) { voice . Audible = false ; } } } } public SetStaffFollow ( staffId , follow ) { const staff = this . staves [ staffId - 1 ] ; staff . following = follow ; if ( follow ) { for ( let idx = 0 , len = staff . Voices . length ; idx < len ; ++ idx ) { const v = staff . Voices [ idx ] ; v . Following = true ; } } else { for ( let idx = 0 , len = staff . Voices . length ; idx < len ; ++ idx ) { const voice = staff . Voices [ idx ] ; let isFollowingInOtherStaves = false ; for ( let idx2 = 0 , len2 = this . Staves . length ; idx2 < len2 ; ++ idx2 ) { const st = this . Staves [ idx2 ] ; if ( st . Id === staffId || ! st . following ) { continue ; } for ( let idx3 = 0 , len3 = st . Voices . length ; idx3 < len3 ; ++ idx3 ) { const v = st . Voices [ idx3 ] ; if ( v === voice ) { isFollowingInOtherStaves = true ; } } } if ( ! isFollowingInOtherStaves ) { voice . Following = false ; } } } } public areAllVoiceVisible ( ) { for ( const voice of this . Voices ) { if ( ! voice . Visible ) { return false ; } } return true ; } public createStaves ( numberOfStaves ) { for ( let i = 0 ; i < numberOfStaves ; i ++ ) { this . staves . push ( new Staff ( this , i + 1 ) ) ; } } public toString ( ) { return `${ this . Name } , id: ${ this . id }, idstring: ${ this . idString }` ; } }