@@ -18,11 +18,20 @@ function createMockAudioContext(currentTime = 100) {
1818 } ) ,
1919 _fireEnded : ( ) => endedListeners . forEach ( ( cb ) => cb ( ) ) ,
2020 } ;
21- const gainNode = {
22- gain : { value : 1 } ,
23- connect : vi . fn ( ) ,
24- disconnect : vi . fn ( ) ,
21+ // Every createGain call returns a distinct node. Sharing one hides graph
22+ // errors because the solo stage can overwrite the authored-volume stage.
23+ const gainNodes : Array < {
24+ gain : { value : number } ;
25+ connect : ReturnType < typeof vi . fn > ;
26+ disconnect : ReturnType < typeof vi . fn > ;
27+ } > = [ ] ;
28+ const makeGain = ( ) => {
29+ const node = { gain : { value : 1 } , connect : vi . fn ( ) , disconnect : vi . fn ( ) } ;
30+ gainNodes . push ( node ) ;
31+ return node ;
2532 } ;
33+ const gainNode = makeGain ( ) ;
34+ let served = 0 ;
2635 const mediaElementSourceNode = {
2736 connect : vi . fn ( ) ,
2837 disconnect : vi . fn ( ) ,
@@ -37,11 +46,11 @@ function createMockAudioContext(currentTime = 100) {
3746 resume : vi . fn ( ) ,
3847 createBufferSource : vi . fn ( ( ) => sourceNode ) ,
3948 createMediaElementSource : vi . fn ( ( ) => mediaElementSourceNode ) ,
40- createGain : vi . fn ( ( ) => gainNode ) ,
49+ createGain : vi . fn ( ( ) => ( served ++ === 0 ? gainNode : makeGain ( ) ) ) ,
4150 destination : { } ,
4251 close : vi . fn ( ) ,
4352 } ;
44- return { ctx, sourceNode, mediaElementSourceNode, gainNode, masterGain, startFn } ;
53+ return { ctx, sourceNode, mediaElementSourceNode, gainNode, gainNodes , masterGain, startFn } ;
4554}
4655
4756function setupTransport ( currentTime = 100 ) {
@@ -112,7 +121,9 @@ describe("WebAudioTransport", () => {
112121 expect ( mock . ctx . createMediaElementSource ) . toHaveBeenCalledWith ( mockEl ) ;
113122 expect ( mock . ctx . createBufferSource ) . not . toHaveBeenCalled ( ) ;
114123 expect ( mock . mediaElementSourceNode . connect ) . toHaveBeenCalled ( ) ;
115- expect ( mock . gainNode . connect ) . toHaveBeenCalledWith ( mock . masterGain ) ;
124+ const [ volumeGain , soloGain ] = mock . gainNodes ;
125+ expect ( volumeGain ?. connect ) . toHaveBeenCalledWith ( soloGain ) ;
126+ expect ( soloGain ?. connect ) . toHaveBeenCalledWith ( mock . masterGain ) ;
116127 expect ( mockEl . muted ) . toBe ( false ) ;
117128 expect ( mockEl . volume ) . toBe ( 1 ) ;
118129 expect ( mock . gainNode . gain . value ) . toBe ( 0.8 ) ;
@@ -737,15 +748,15 @@ describe("WebAudioTransport", () => {
737748 document . body . innerHTML = "" ;
738749 } ) ;
739750
740- it ( "routes an ungrouped clip straight to master through its own gain " , async ( ) => {
751+ it ( "routes an ungrouped clip to master through its own solo stage " , async ( ) => {
741752 const { transport, mock, gen } = setupGroupTransport ( ) ;
742753
743754 await scheduleGrouped ( transport , gen , "lone" ) ;
744755
745- // One gain per clip now that solo is gone — it goes straight to master.
746- expect ( mock . gainNodes ) . toHaveLength ( 1 ) ;
747- const [ clipGain ] = mock . gainNodes ;
748- expect ( clipGain ! . connect ) . toHaveBeenCalledWith ( mock . masterGain ) ;
756+ expect ( mock . gainNodes ) . toHaveLength ( 2 ) ;
757+ const [ clipGain , soloGain ] = mock . gainNodes ;
758+ expect ( clipGain ! . connect ) . toHaveBeenCalledWith ( soloGain ) ;
759+ expect ( soloGain ! . connect ) . toHaveBeenCalledWith ( mock . masterGain ) ;
749760 } ) ;
750761
751762 // The media-element transport is the PRIMARY path for audio — the runtime
@@ -790,7 +801,9 @@ describe("WebAudioTransport", () => {
790801 await transport . scheduleMediaElementPlayback ( el , 0 , 0 , 0 , 1 , gen , 1 ) ;
791802
792803 const clipGain = mock . gainNodes [ 0 ] ! ;
793- expect ( clipGain . connect ) . toHaveBeenCalledWith ( firstGroupInput ( mock ) ) ;
804+ const soloGain = mock . gainNodes [ 5 ] ! ;
805+ expect ( clipGain . connect ) . toHaveBeenCalledWith ( soloGain ) ;
806+ expect ( soloGain . connect ) . toHaveBeenCalledWith ( firstGroupInput ( mock ) ) ;
794807 expect ( clipGain . connect ) . not . toHaveBeenCalledWith ( mock . masterGain ) ;
795808 } ) ;
796809
@@ -800,8 +813,9 @@ describe("WebAudioTransport", () => {
800813
801814 await transport . scheduleMediaElementPlayback ( el , 0 , 0 , 0 , 1 , gen , 1 ) ;
802815
803- expect ( mock . gainNodes ) . toHaveLength ( 1 ) ;
804- expect ( mock . gainNodes [ 0 ] ! . connect ) . toHaveBeenCalledWith ( mock . masterGain ) ;
816+ expect ( mock . gainNodes ) . toHaveLength ( 2 ) ;
817+ expect ( mock . gainNodes [ 0 ] ! . connect ) . toHaveBeenCalledWith ( mock . gainNodes [ 1 ] ) ;
818+ expect ( mock . gainNodes [ 1 ] ! . connect ) . toHaveBeenCalledWith ( mock . masterGain ) ;
805819 } ) ;
806820
807821 it ( "two members of the same group land on ONE shared group gain, not master directly" , async ( ) => {
@@ -810,20 +824,23 @@ describe("WebAudioTransport", () => {
810824 await scheduleGrouped ( transport , gen , "a" , "vo" ) ;
811825 await scheduleGrouped ( transport , gen , "b" , "vo" ) ;
812826
813- // Creation order for a: a-gain(0), groupInput(1), groupOutput(2),
814- // muteGain(3), fader(4) — the group bus is built lazily inside a's
815- // schedule call. Then b: b-gain(5).
816- expect ( mock . gainNodes . length ) . toBeGreaterThanOrEqual ( 6 ) ;
827+ // Creation order for a: gain(0), group bus(1–4), solo(5). Then b uses
828+ // gain(6), solo(7); both solo stages feed the one shared group input.
829+ expect ( mock . gainNodes . length ) . toBeGreaterThanOrEqual ( 8 ) ;
817830 const aGain = mock . gainNodes [ 0 ] ! ;
831+ const aSolo = mock . gainNodes [ 5 ] ! ;
818832 const groupInput = firstGroupInput ( mock ) ;
819833 const groupOutput = mock . gainNodes [ 2 ] ! ;
820834 const muteGain = mock . gainNodes [ 3 ] ! ;
821835 const fader = mock . gainNodes [ 4 ] ! ;
822- const bGain = mock . gainNodes [ 5 ] ! ;
823-
824- // Both members feed the shared bus — neither connects straight to master.
825- expect ( aGain . connect ) . toHaveBeenCalledWith ( groupInput ) ;
826- expect ( bGain . connect ) . toHaveBeenCalledWith ( groupInput ) ;
836+ const bGain = mock . gainNodes [ 6 ] ! ;
837+ const bSolo = mock . gainNodes [ 7 ] ! ;
838+
839+ // Both members feed their own solo stage, then the shared bus.
840+ expect ( aGain . connect ) . toHaveBeenCalledWith ( aSolo ) ;
841+ expect ( bGain . connect ) . toHaveBeenCalledWith ( bSolo ) ;
842+ expect ( aSolo . connect ) . toHaveBeenCalledWith ( groupInput ) ;
843+ expect ( bSolo . connect ) . toHaveBeenCalledWith ( groupInput ) ;
827844 expect ( aGain . connect ) . not . toHaveBeenCalledWith ( mock . masterGain ) ;
828845 expect ( bGain . connect ) . not . toHaveBeenCalledWith ( mock . masterGain ) ;
829846
@@ -843,11 +860,11 @@ describe("WebAudioTransport", () => {
843860 const { transport, mock, gen } = setupGroupTransport ( ) ;
844861
845862 await scheduleGrouped ( transport , gen , "a" , "vo" ) ;
846- const gainCountAfterFirst = mock . gainNodes . length ; // a-gain + group input/output/mute/fader
863+ const gainCountAfterFirst = mock . gainNodes . length ;
847864 await scheduleGrouped ( transport , gen , "b" , "vo" ) ;
848865
849- // Only b's own gain is new — no second group bus minted.
850- expect ( mock . gainNodes . length ) . toBe ( gainCountAfterFirst + 1 ) ;
866+ // Only b's volume and solo gains are new — no second group bus minted.
867+ expect ( mock . gainNodes . length ) . toBe ( gainCountAfterFirst + 2 ) ;
851868 } ) ;
852869
853870 it ( "a group id with no matching <hf-audio-group> element still gets a flat bus" , async ( ) => {
@@ -913,6 +930,45 @@ describe("WebAudioTransport", () => {
913930 expect ( mock . gainNodes . filter ( ( n ) => n === groupInput ) ) . toHaveLength ( 1 ) ;
914931 } ) ;
915932
933+ describe ( 'solo — "Hear only this" compatibility bridge' , ( ) => {
934+ it ( "silences non-soloed members without attenuating their shared group bus" , async ( ) => {
935+ const { transport, mock, gen } = setupGroupTransport ( ) ;
936+ await scheduleGrouped ( transport , gen , "a" , "vo" ) ;
937+ await scheduleGrouped ( transport , gen , "b" , "vo" ) ;
938+
939+ transport . setSolo ( new Set ( [ "a" ] ) ) ;
940+
941+ expect ( mock . gainNodes [ 5 ] ! . gain . value ) . toBe ( 1 ) ;
942+ expect ( mock . gainNodes [ 7 ] ! . gain . value ) . toBe ( 0 ) ;
943+ expect ( firstGroupInput ( mock ) . gain . value ) . toBe ( 1 ) ;
944+ } ) ;
945+
946+ it ( "soloing a group keeps every member of that group audible" , async ( ) => {
947+ const { transport, mock, gen } = setupGroupTransport ( ) ;
948+ await scheduleGrouped ( transport , gen , "a" , "vo" ) ;
949+ await scheduleGrouped ( transport , gen , "b" , "vo" ) ;
950+
951+ transport . setSolo ( new Set ( [ "vo" ] ) ) ;
952+
953+ expect ( mock . gainNodes [ 5 ] ! . gain . value ) . toBe ( 1 ) ;
954+ expect ( mock . gainNodes [ 7 ] ! . gain . value ) . toBe ( 1 ) ;
955+ } ) ;
956+
957+ it ( "applies an existing solo to newly scheduled clips and restores them when cleared" , async ( ) => {
958+ const { transport, mock, gen } = setupGroupTransport ( ) ;
959+ transport . setSolo ( new Set ( [ "a" ] ) ) ;
960+ await scheduleGrouped ( transport , gen , "a" ) ;
961+ await scheduleGrouped ( transport , gen , "b" ) ;
962+
963+ expect ( mock . gainNodes [ 1 ] ! . gain . value ) . toBe ( 1 ) ;
964+ expect ( mock . gainNodes [ 3 ] ! . gain . value ) . toBe ( 0 ) ;
965+
966+ transport . setSolo ( new Set ( ) ) ;
967+ expect ( mock . gainNodes [ 1 ] ! . gain . value ) . toBe ( 1 ) ;
968+ expect ( mock . gainNodes [ 3 ] ! . gain . value ) . toBe ( 1 ) ;
969+ } ) ;
970+ } ) ;
971+
916972 // Surviving stopAll() is the point of the bus — and the trap. Its envelopes
917973 // were booked against the FIRST pass's absolute context times, so a replay
918974 // or a seek left the fader holding that pass's last value: 0 after a
0 commit comments