@@ -29,6 +29,8 @@ export type useEditSongProviderType = {
29
29
register : UseFormRegister < EditSongForm > ;
30
30
errors : FieldErrors < EditSongForm > ;
31
31
song : SongFileType | null ;
32
+ instrumentSounds : string [ ] ;
33
+ setInstrumentSound : ( index : number , value : string ) => void ;
32
34
sendError : string | null ;
33
35
isSubmitting : boolean ;
34
36
loadSong : ( id : string , username : string , song : UploadSongDtoType ) => void ;
@@ -50,6 +52,7 @@ export const EditSongProvider = ({
50
52
} ) ;
51
53
52
54
const [ song , setSong ] = useState < SongFileType | null > ( null ) ;
55
+ const [ instrumentSounds , setInstrumentSounds ] = useState < string [ ] > ( [ ] ) ;
53
56
const [ sendError , setSendError ] = useState < string | null > ( null ) ;
54
57
const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
55
58
@@ -248,20 +251,26 @@ export const EditSongProvider = ({
248
251
// convert to song
249
252
const song = await parseSongFromBuffer ( songFile ) ;
250
253
251
- // pad instruments array for safety
252
- const songInstruments = Array ( song . instruments . length ) . fill ( '' ) ;
253
-
254
- songData . customInstruments . forEach ( ( instrument , index ) => {
255
- songInstruments [ index ] = instrument ;
256
- } ) ;
257
-
254
+ // set instruments array
255
+ const songInstruments = songData . customInstruments ;
256
+ setInstrumentSounds ( songInstruments ) ;
258
257
formMethods . setValue ( 'customInstruments' , songInstruments ) ;
259
258
260
259
setSong ( song ) ;
261
260
} ,
262
261
[ formMethods , setSong ] ,
263
262
) ;
264
263
264
+ const setInstrumentSound = useCallback (
265
+ ( index : number , value : string ) => {
266
+ const newValues = [ ...instrumentSounds ] ;
267
+ newValues [ index ] = value ;
268
+ setInstrumentSounds ( newValues ) ;
269
+ formMethods . setValue ( 'customInstruments' , newValues ) ;
270
+ } ,
271
+ [ formMethods , instrumentSounds ] ,
272
+ ) ;
273
+
265
274
const setSongId = useCallback (
266
275
( id : string ) => formMethods . setValue ( 'id' , id ) ,
267
276
[ formMethods ] ,
@@ -289,6 +298,8 @@ export const EditSongProvider = ({
289
298
value = { {
290
299
formMethods,
291
300
submitSong,
301
+ instrumentSounds,
302
+ setInstrumentSound,
292
303
register,
293
304
errors,
294
305
song,
0 commit comments