Skip to content

Commit

Permalink
多音轨数据结构初步完成
Browse files Browse the repository at this point in the history
  • Loading branch information
madderscientist committed Jan 26, 2024
1 parent ff2b40c commit e8f35ea
Show file tree
Hide file tree
Showing 15 changed files with 772 additions and 167 deletions.
38 changes: 33 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,15 @@ function App() {
this.MidiAction.midi = JSON.parse(nextState);
this.MidiAction.selected = this.MidiAction.midi.filter((obj) => obj.selected);
}
},
'Ctrl+A': () => {

},
'Ctrl+C': () => {

},
'Ctrl+V': () => {

}
};
/**
Expand Down Expand Up @@ -677,17 +686,35 @@ function App() {
}
}
},
onfile: (file) => {
document.body.insertAdjacentHTML('afterbegin', `<div id="request-cover"><div class="card hvCenter"><label class="title">${file.name}</label><div><span>每秒的次数:</span><input type="number" name="ui-ask" value="10" min="1" max="100"></div><div><span>标准频率A4=</span><input type="number" name="ui-ask" value="440" step="0.1" min="55"></div><div>分析声道:</div><div><input type="radio" name="ui-ask" value="4" checked>Stereo<input type="radio" name="ui-ask" value="2">L+R<input type="radio" name="ui-ask" value="3">L-R<input type="radio" name="ui-ask" value="0">L<input type="radio" name="ui-ask" value="1">R</div><div><button id="ui-confirm">解析</button><button id="ui-cancel">取消</button></div></div></div>`);
onfile: (file) => { // 依赖askUI.css
let tempDiv = document.createElement('div');
tempDiv.innerHTML = `
<div class="request-cover">
<div class="card hvCenter"><label class="title">${file.name}</label>
<div><span>每秒的次数:</span><input type="number" name="ui-ask" value="10" min="1" max="100"></div>
<div><span>标准频率A4=</span><input type="number" name="ui-ask" value="440" step="0.1" min="55"></div>
<div>分析声道:</div>
<div>
<input type="radio" name="ui-ask" value="4" checked>Stereo
<input type="radio" name="ui-ask" value="2">L+R
<input type="radio" name="ui-ask" value="3">L-R
<input type="radio" name="ui-ask" value="0">L
<input type="radio" name="ui-ask" value="1">R
</div>
<div><button class="ui-cancel">取消</button><button class="ui-confirm">解析</button></div>
</div>
</div>`;
this.AudioPlayer.name = file.name;
if (!this.audioBuffer) this.audioContext = new AudioContext({ sampleRate: 44100 });
function close() { document.getElementById('request-cover').remove(); }
document.getElementById('ui-cancel').onclick = () => {
const ui = tempDiv.firstChild;
let btns = ui.getElementsByTagName('button');
btns[0].onclick = () => {
close(); this.AudioPlayer.audio.src = '';
};
document.getElementById('ui-confirm').onclick = () => {
btns[1].onclick = () => {
// 获取分析参数
const params = document.getElementsByName('ui-ask');
const params = ui.querySelectorAll('[name="ui-ask"]'); // getElementsByName只能在document中用
let tNum = params[0].value;
let A4 = params[1].value;
let channel = 4;
Expand All @@ -712,6 +739,7 @@ function App() {
this.AudioPlayer.audio.src = URL.createObjectURL(new Blob([e.target.result]));
}; fileReader.readAsArrayBuffer(file);
};
document.body.insertBefore(ui, document.body.firstChild); // 插入body的最前面
}
};
//========= 事件注册 =========//
Expand Down
Loading

1 comment on commit e8f35ea

@madderscientist
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多音轨

对多音轨进行了深入的思考和实践,由于缺少合成器所以没有合并到主项目上。思路体现在todo.md中。
设计了一个可拖拽列表,完成了样式和逻辑,并在此基础上设计了音轨列表ChannelList类,主要负责用ui更改数据。
样式使用了阿里图标库;拖拽排序放弃了动画效果(除颤太难了)。
这个ui类应该较为完善了,没有封装成自定义标签因为顾及了其他浏览器。

右键菜单

稍微升级了一下,体现为:

  • 可以设置选项的响应事件(新增event属性,默认“click”触发callback)
  • 可以设置完成选择后是否关闭右键菜单(由callback的返回值确定)
  • 取消右键的右键

杂项

修复了app.js没有测试的弹出窗选择器的bug;弹出窗的css结构更改,id改为class,使弹出窗其可以复用和同时出现;删了index.html中不必要的东西。

Please sign in to comment.