您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637
  1. import abcjs from 'abcjs'
  2. import { useEffect, useRef } from 'react'
  3. import 'abcjs/abcjs-audio.css'
  4. const MarkdownMusic = ({ children }: { children: React.ReactNode }) => {
  5. const containerRef = useRef<HTMLDivElement>(null)
  6. const controlsRef = useRef<HTMLDivElement>(null)
  7. useEffect(() => {
  8. if (containerRef.current && controlsRef.current) {
  9. if (typeof children === 'string') {
  10. const visualObjs = abcjs.renderAbc(containerRef.current, children, {
  11. add_classes: true, // Add classes to SVG elements for cursor tracking
  12. responsive: 'resize', // Make notation responsive
  13. })
  14. const synthControl = new abcjs.synth.SynthController()
  15. synthControl.load(controlsRef.current, {}, { displayPlay: true })
  16. const synth = new abcjs.synth.CreateSynth()
  17. const visualObj = visualObjs[0]
  18. synth.init({ visualObj }).then(() => {
  19. synthControl.setTune(visualObj, false)
  20. })
  21. containerRef.current.style.overflow = 'auto'
  22. }
  23. }
  24. }, [children])
  25. return (
  26. <div style={{ minWidth: '100%', overflow: 'auto' }}>
  27. <div ref={containerRef} />
  28. <div ref={controlsRef} />
  29. </div>
  30. )
  31. }
  32. MarkdownMusic.displayName = 'MarkdownMusic'
  33. export default MarkdownMusic