123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- import { reactive } from "vue";
- import { IAbc, IMeasure, INote } from "../types";
- import { getImage } from "./images";
- export const ABC_DATA = {
- /** 音符 */
- types: [
- { name: "全音符", value: "4", icon: "icon-quanyinfu" },
- { name: "二分音符", value: "2", icon: "icon-a-2fenyinfu" },
- { name: "四分音符", value: "", icon: "icon-a-4fenyinfu" },
- { name: "八分音符", value: "/", icon: "icon-a-8fenyinfu" },
- { name: "十六分音符", value: "//", icon: "icon-a-16fenyinfu" },
- { name: "三十二分音符", value: "///", icon: "icon-a-32fenyinfu" },
- ],
- /** 休止符 */
- reset: [{ name: "休止符", value: "z", icon: "icon-a-4fenxiuzhifu" }],
- /** 临时升降记号 */
- accidentals: [
- { name: "重降号", value: "__", icon: getImage("icon_2.png") },
- { name: "降号", value: "_", icon: getImage("icon_3.png") },
- { name: "还原号", value: "=", icon: getImage("icon_4.png") },
- { name: "升号", value: "^", icon: getImage("icon_5.png") },
- { name: "重升号", value: "^^", icon: getImage("icon_6.png") },
- ],
- /** 谱号 */
- clef: [
- { name: "低音谱号", value: "K:bass", icon: "icon-puhao-diyinpuhao" },
- { name: "高音谱号", value: "K:treble", icon: "icon-puhao-gaoyinpuhao" },
- { name: "次中音谱号", value: "K:tenor", icon: "icon-puhao-cizhongyinpuhao" },
- { name: "中音谱号", value: "K:alto", icon: "icon-puhao-zhongyinpuhao" },
- { name: "打击乐谱号", value: "K:perc", icon: "icon-puhao-gupu" },
- ],
- /** 调号 */
- key: [
- { name: "C大调", value: "K:C", icon: "icon-a-diaohao-cdadiaoaxiaodiao1" },
- { name: "G大调", value: "K:G", icon: "icon-a-diaohao-Gdadiaoexiaodiao" },
- { name: "D大调", value: "K:D", icon: "icon-a-diaohao-Ddaxiaoexiaodiao" },
- { name: "A大调", value: "K:A", icon: "icon-a-diaohao-Adadiaofxiaodiao" },
- { name: "E大调", value: "K:E", icon: "icon-a-diaohao-edadiaocxiaodiao" },
- { name: "B大调", value: "K:B", icon: "icon-a-diaohao-bdadiaogxiaodiao" },
- { name: "F#大调", value: "K:F#", icon: "icon-a-diaohao-fdadiaodxiaodiao" },
- { name: "C#大调", value: "K:C#", icon: "icon-a-diaohao-cdadiaoaxiaodiao" },
- { name: "F大调", value: "K:F", icon: "icon-a-diaohao-fdadiaodxiaodiao1" },
- { name: "Bb大调", value: "K:Bb", icon: "icon-a-diaohao-bbdadiaogxiaodiao" },
- { name: "Eb大调", value: "K:Eb", icon: "icon-a-diaohao-ebdadiaocxiaodiao" },
- { name: "Ab大调", value: "K:Ab", icon: "icon-a-diaohao-abdadiaofxiaodiao" },
- { name: "Db大调", value: "K:Db", icon: "icon-a-diaohao-dbdadiaobbxiaodiao" },
- { name: "Gb大调", value: "K:Gb", icon: "icon-a-diaohao-gbdadiaoebxiaodiao" },
- { name: "Cb大调", value: "K:Cb", icon: "icon-a-diaohao-cbdadiaoabxiaodiao" },
- ],
- /** 拍号 */
- meter: [
- { name: "2/2", value: "M:2/2", icon: "icon-paihao-22" },
- { name: "2/4", value: "M:2/4", icon: "icon-paihao-24" },
- { name: "3/4", value: "M:3/4", icon: "icon-paihao-34" },
- { name: "4/4", value: "M:4/4", icon: "icon-paihao-44" },
- { name: "3/8", value: "M:3/8", icon: "icon-paihao-38" },
- { name: "6/8", value: "M:6/8", icon: "icon-paihao-68" },
- { name: "9/8", value: "M:9/8", icon: "icon-paihao-98" },
- { name: "12/8", value: "M:12/8", icon: "icon-a-paihao-128" },
- ],
- /** 演奏技法 */
- play: [
- { name: "加强音", value: "!marcato!", icon: getImage("icon_9.png") },
- { name: "重音", value: "!>!", icon: getImage("icon_10.png") },
- { name: "保持音", value: "!tenuto!", icon: getImage("icon_11.png") },
- { name: "断音", value: "!wedge!", icon: getImage("icon_12.png") },
- { name: "花型重复记号", value: "S", icon: "icon-fanfuyutiaoyue-sbiao" },
- { name: "Coda", value: "O", icon: "icon-fanfuyutiaoyue-weisheng" },
- { name: "波音", value: "P", icon: "icon-e1" },
- { name: "逆波音", value: "M", icon: "icon-d1" },
- { name: "换气符号(逗号)", value: "!breath!", icon: "icon-c1" },
- { name: "回音", value: "!turn!", icon: "icon-b" },
- // { name: "逆回音", value: "!turnx!", icon: "icon-b" },
- { name: "颤音", value: "T", icon: "icon-a1" },
- { name: "跳音", value: ".", icon: "icon-a-zoufajihao-duanzouhaoshang" },
- { name: "延迟音记号", value: "!fermata!", icon: "icon-f1" },
- ],
- /** 小节线 */
- bar: [
- { name: "单小节线", value: "|", icon: "icon-xiaojiexian-danxiaojiexian" },
- { name: "双小节线", value: "||", icon: "icon-xiaojiexian-shuangxiaojiexian" },
- { name: "结束线", value: "|]", icon: "icon-xiaojiexian-zhongzhixiaojiexian" },
- { name: "重复线开始", value: "|:", icon: "icon-a-xiaojiexian-zuoqishifanfuhao" },
- { name: "重复线结束", value: ":|", icon: "icon-a-xiaojiexian-youzhongzhifanfuhao" },
- { name: "双重复", value: "::", icon: "icon-xiaojiexian-jieshuyuqishifanfubiaozhi" },
- ],
- /** 连线 */
- tie: [
- { name: "延音线", value: "-", icon: getImage("icon_7.png") }, // 延音必须同音高
- { name: "连音线", value: ["(", ")"], icon: getImage("icon_8.png") }, // 需要是音符和结束音符,最低两个音符
- ],
- /** 8度线 */
- octave: [
- // 暂不支持
- { name: "高8度开始", value: ["!8va(!", "!8va)!"] },
- { name: "低8度", value: ["!8vb(!", "!8vb)!"] },
- ],
- /** 力度记号 */
- dynamics: [
- { name: "极弱", value: "!ppp!", icon: "icon-lidujihao-ppp" },
- { name: "很弱", value: "!pp!", icon: "icon-lidujihao-pp" },
- { name: "弱", value: "!p!", icon: "icon-lidujihao-p" },
- { name: "中弱", value: "!mp!", icon: "icon-lidujihao-mp" },
- { name: "中强", value: "!mf!", icon: "icon-lidujihao-mf" },
- { name: "强", value: "!f!", icon: "icon-lidujihao-f" },
- { name: "很强", value: "!ff!", icon: "icon-lidujihao-ff" },
- { name: "极强", value: "!fff!", icon: "icon-lidujihao-fff" },
- { name: "渐强", value: ["!<(!", "!<)!"], icon: "icon-lidujihao-jianqianghao" }, // 需要是音符范围,最低两个音
- { name: "渐弱", value: ["!>(!", "!>)!"], icon: "icon-lidujihao-jianruohao" }, //需要是音符范围,最低两个音
- ],
- repeat: [
- { name: "第一跳跃", value: "1", icon: "icon-fanfuyutiaoyue-diyitiaoyuehao" },
- { name: "第二跳跃", value: "2", icon: "icon-fanfuyutiaoyue-di2kaifangtiaoyuehao" },
- // { name: "重复3房", value: "3", icon: "" },
- // { name: "重复4房", value: "4", icon: "" },
- ],
- speeds: [
- { name: "60", value: "Q:1/4=60", icon: "" },
- { name: "70", value: "Q:1/4=70", icon: "" },
- { name: "80", value: "Q:1/4=80", icon: "" },
- { name: "90", value: "Q:1/4=90", icon: "" },
- { name: "100", value: "Q:1/4=100", icon: "" },
- { name: "120", value: "Q:1/4=120", icon: "" },
- ],
- slus: [
- { name: "3连音", value: '(3', icon: '' },
- { name: "4连音", value: '(4', icon: '' },
- { name: "5连音", value: '(5', icon: '' },
- { name: "6连音", value: '(6', icon: '' },
- { name: "7连音", value: '(7', icon: '' },
- ],
- /** 3连音等多连音
- * 1. 将连音的音符小括号起来,并在括号前加上数字表示连音的音符数
- */
- };
- export const settings = reactive({
- /** 光标跟随 音符, 节拍 */
- cursorType: 'note' as 'note' | 'beat',
- })
- export const createNote = (options: Partial<INote>): INote => {
- return {
- accidental: options.accidental || "",
- content: options.content || "",
- noteType: options.noteType || "",
- meter: options.meter || "",
- clef: options.clef || "",
- play: options.play || [],
- key: options.key || "",
- speed: options.speed || "",
- dynamics: options.dynamics || "",
- dCode: options.dCode || "",
- tie: options.tie || "",
- tCode: options.tCode || "",
- dot: options.dot || "",
- slus: options.slus || "",
- };
- };
- export const createMeasure = (): IMeasure => {
- return {
- notes: [
- createNote({
- content: "z",
- }),
- ],
- barline: "|",
- repeat: "",
- measureNumber: 0,
- celf: "",
- key: "",
- };
- };
- /** 生成小节 */
- export const renderMeasures = (abc: IAbc) => {
- // console.log("🚀 ~ abc:", abc)
- let text = `X:1\n`;
- abc.title && (text += abc.title + "\n");
- abc.celf && (text += abc.celf + "\n");
- abc.meter && (text += abc.meter + "\n");
- abc.minUnit && (text += abc.minUnit + "\n");
- abc.speed && (text += abc.speed + "\n");
- abc.key && (text += abc.key + "\n");
- const measures = abc.measures;
- for (let i = 0; i < measures.length; i++) {
- const measure = measures[i];
- text += measure.repeat;
- for (let j = 0; j < measure.notes.length; j++) {
- const note = measure.notes[j];
- const playStr = note.play?.join("") || "";
- text += note.clef; // 谱号
- text += note.key; // 调号
- text += note.speed; // 速度
- text += note.meter; // 拍号
- text += note.slus; // 3连音
- if (note.tie.includes("(")) {
- // 连音线 前
- text += note.tie;
- }
- text += `"<${i + "." + j}"`; // 音符 id
- text += playStr; // 演奏技法
- text += note.dynamics; // 力度符号
- text += note.accidental; // 临时升降记号
- text += note.content; // 音符
- text += note.noteType; // 音符类型
- text += note.dot; // 附点
- if (note.tie.includes(")")) {
- // 连音线 后
- text += note.tie;
- }
- }
- text += measure.barline;
- // text += `"${i}"` + measure.barline;
- if (i > 0 && i % 4 === 0) {
- text += "\n";
- }
- }
- // console.log(text)
- return text;
- };
|