te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>typescript - InvalidStateError on sampler.triggerAttackRelease - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

typescript - InvalidStateError on sampler.triggerAttackRelease - Stack Overflow

programmeradmin3浏览0评论

I am trying to make a small beatbox with tonejs and its sampler within a Vue3 typescript application.

It converts sequences of integers into drum patterns by first converting them to binary for polyphony.

You can see the whole code here:

And especially: .vue

It is even deployed here: /

I have previously written a small sequencer with a simple oscillator in a similar fashion and it works relatively well (/); this new beatbox app was even started as a copy of it. I wonder why I can't get the sampler to work in real time.

The download midi file functionality works as intended so the sequence of notes and velocities are correct until proven otherwise.

The mp3 samples for the beatbox seems to be loaded correctly.

But, on the call to triggerAttackRelease (there is only one in the code in the playStep method) I always get an InvalidStateError.

Could one of you sweethearts possibly help me debug this?

Have a nice day.

I am trying to make a small beatbox with tonejs and its sampler within a Vue3 typescript application.

It converts sequences of integers into drum patterns by first converting them to binary for polyphony.

You can see the whole code here: https://github/ncg777/super-beatbox-3000

And especially: https://github/ncg777/super-beatbox-3000/blob/main/src/App.vue

It is even deployed here: https://ncg777.github.io/super-beatbox-3000/

I have previously written a small sequencer with a simple oscillator in a similar fashion and it works relatively well (https://ncg777.github.io/super-sequencer-3000/); this new beatbox app was even started as a copy of it. I wonder why I can't get the sampler to work in real time.

The download midi file functionality works as intended so the sequence of notes and velocities are correct until proven otherwise.

The mp3 samples for the beatbox seems to be loaded correctly.

But, on the call to triggerAttackRelease (there is only one in the code in the playStep method) I always get an InvalidStateError.

Could one of you sweethearts possibly help me debug this?

Have a nice day.

Share Improve this question edited 2 days ago Nicolas Couture-Grenier asked 2 days ago Nicolas Couture-GrenierNicolas Couture-Grenier 1011 silver badge9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

It looks like this is an unwanted consequence of how Vue.js implements what it calls Reactivity.

The error originates from here: https://github/chrisguttandin/standardized-audio-context/blob/11cde3f52dad83b6e3f971b3cb3dc4d98ad59b3b/src/factories/gain-node-constructor.ts#L23.

When creating a GainNode standardized-audio-context tries to find the native AudioContext which should be used to create the native GainNode. But when everything gets wrapped with a Proxy it is essentially a different object when comparing it with the original value. In the end standardized-audio-context can't find the native AudioContext anymore and throws an error.

It's probably best to not put anything which belongs to Tone.js inside the state managed by Vue.js. But the easiest solution I can think of to make your code work is by using markRaw().

Instead of defining your component like this ...

import { defineComponent } from 'vue';
// ... other imports

export default defineComponent({
  // ...
  data() {
    // ...
    sampler: new Tone.Sampler({ /* ... */ })
    // ...
  }
  // ...
});

... you could simply wrap the sampler with markRaw():

import { defineComponent, markRaw } from 'vue';
// ... other imports

export default defineComponent({
  // ...
  data() {
    // ...
    sampler: markRaw(
      new Tone.Sampler({ /* ... */ })
    )
    // ...
  }
  // ...
});

By the way your code needs one more tweak to work. The onload callback of the Sampler doesn't work because this refers to the context around the arrow function. In this case it's the component.

The following line ...

onload: () => {this.toDestination()},

... should become:

onload: () => {this.sampler.toDestination()},
发布评论

评论列表(0)

  1. 暂无评论