Skip to content

Commit

Permalink
Fixed custom sounds list issue
Browse files Browse the repository at this point in the history
When a custom sound was uploaded a long list of unrecognisable sounds.
  • Loading branch information
muganwas committed Apr 7, 2022
1 parent cc617b6 commit 3770134
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
21 changes: 14 additions & 7 deletions src/audio-engine/Instruments.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const Instruments = {
options = _.sortBy(options, "label");
return options;
},
getInstrumentArticulationOptions(instrumentName, userId) {
getInstrumentArticulationOptions(instrumentName, userId, instrument) {
// console.log('getInstrumentArticulationOptions()', instrumentName);
if (instrumentName !== 'custom') {
let options = [];
Expand All @@ -114,13 +114,20 @@ const Instruments = {
} else {
let options = []
// console.log('CustomSamples.samples', CustomSamples.samples);
for (let [id, sample] of Object.entries(CustomSamples.samples)) {
if (sample.createdBy === userId) {
options.push({
name: sample.name,
value: id
})
if (instrumentName !== 'custom' && !instrument.sampleId)
for (let [id, sample] of Object.entries(CustomSamples.samples)) {
if (sample.createdBy === userId) {
options.push({
name: sample.name,
value: id
})
}
}
else {
options.push({
name: instrument.displayName,
value: instrument.displayName
})
}
// console.log('got sample options', options);
return options
Expand Down
1 change: 1 addition & 0 deletions src/components/dialogs/CreateRoundModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ const CreateRoundModal = ({
urls && Array.isArray(urls) && urls.forEach(async url => {
let sample = getDefaultSample(user.id)
sample.remoteURL = url
sample.displayName = 'Custom'
await firebase.createSample(sample)
newSamples.push(sample)
if (newSamples.length === urls.length) {
Expand Down
6 changes: 4 additions & 2 deletions src/components/play/layer-settings/LayerInstrument.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ const LayerInstrument = ({
}) => {
const [selectedInstrument, setSelectedInstrument] = React.useState(selectedLayer.instrument.sampler)
const [selectedArticulation, setSelectedArticulation] = React.useState(selectedLayer.instrument.sample)
const [selectedInstrumentFull, setSelectedInstrumentFull] = React.useState(selectedLayer.instrument)
const dispatch = useDispatch();
const instrumentOptions = Instruments.getInstrumentOptions(false)
const articulationOptions = Instruments.getInstrumentArticulationOptions(selectedInstrument, user.id)
const articulationOptions = Instruments.getInstrumentArticulationOptions(selectedInstrument, user.id, selectedInstrumentFull)
const firebase = useContext(FirebaseContext);

const onInstrumentSelect = async (instrument) => {
Expand All @@ -56,9 +57,10 @@ const LayerInstrument = ({
}

useEffect(() => {
setSelectedInstrumentFull(selectedLayer.instrument)
setSelectedInstrument(selectedLayer.instrument.sampler)
setSelectedArticulation(selectedLayer.instrument.sample)
hideAllLayerInspectorModals();
hideAllLayerInspectorModals()
}, [selectedLayer, hideAllLayerInspectorModals])

const onArticulationSelect = async (articulation) => {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/defaultData.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export const generateLayers = async (samples, userId) => {
"instrument": "Sampler",
"sampler": 'custom',
"sample": articulation.name,
"sampleId": sample.id
"sampleId": sample.id,
"displayName": sample.displayName
})
layers.push(layer)
if (layers.length === samples.length)
Expand Down

0 comments on commit 3770134

Please sign in to comment.