FormidableLabs / react-music

Make beats with React!
http://reactmusic.surge.sh
MIT License
2.73k stars 197 forks source link

note-parser not working when using as a library in another project #45

Open bgruber opened 7 years ago

bgruber commented 7 years ago

Hi!

Synthesizers work great for me in the demo project. However, when I add react-music as a dependency to another project, I'm unable to use Synth or Monosynth, seemingly because of an error using note-parser:

Uncaught TypeError: Cannot read property 'freq' of undefined
    at Monosynth.createOscillator (monosynth.js:147)
    at Monosynth.playStep (monosynth.js:163)
    at Scheduler.process (scheduler.js:119)
    at loop (scheduler.js:34)

The Sampler instrument works fine.

paulsoh commented 7 years ago

I think this is a note-parser package issue. <Synth /> and <Monosynth /> both use parser.freq and it seems like depending on what kind of syntax you're using it works on some environments where in other it doesn't (In my case, i was working on a react app using create-react-app)

I had to move the entire react-music src/ folder to inside of my react project and had to switch out all the import parser from 'note-parser' to var parser = require('parser')

and now it seems like it's working! Not elegant but a workaround for now.

Inside my apps

import {
  Analyser,
  Song,
  Sequencer,
  Sampler,
  Synth,
} from '../ReactMusic';

Inside Monosynth, Synth

var parser = require('note-parser');
MariaPet commented 6 years ago

It's not the right solution but it works temporarily for me if I change line 128 in node_modules/react-music/lib/components/synth from this:

// osc.frequency.value = _noteParser2.default.freq(transposed);

to this:

osc.frequency.value = _noteParser2.freq(transposed);

_noteParser2.default is undefined

Would be nice if that could be fixed in a new release.

micaelmbagira commented 5 years ago

Is there an update on this?

x5engine commented 4 years ago

Is there an update on this?

hazem3500 commented 3 years ago

It's not the right solution but it works temporarily for me if I change line 128 in node_modules/react-music/lib/components/synth from this:

// osc.frequency.value = _noteParser2.default.freq(transposed);

to this:

osc.frequency.value = _noteParser2.freq(transposed);

_noteParser2.default is undefined

Would be nice if that could be fixed in a new release.

This worked for me 👍!