Home Reference Source

cables_dev/cables_ui/src/ui/components/tabs/meta_keyframes.js

  1. import defaultOps from "../../defaultops.js";
  2. import ModalDialog from "../../dialogs/modaldialog.js";
  3. import { getHandleBarHtml } from "../../utils/handlebars.js";
  4. import userSettings from "../usersettings.js";
  5.  
  6. CABLES = CABLES || {};
  7. CABLES.UI = CABLES.UI || {};
  8.  
  9. export default class MetaKeyframes
  10. {
  11. constructor(tabs)
  12. {
  13. this.anim = null;
  14. this._tab = new CABLES.UI.Tab("keyframes", { "icon": "clock", "infotext": "tab_keyframes", "padding": true, "singleton": true });
  15. tabs.addTab(this._tab);
  16. // this._tab.addEventListener("onActivate", function ()
  17. // {
  18. this.show();
  19. // }.bind(this));
  20. }
  21.  
  22. update()
  23. {
  24. this.show();
  25. }
  26.  
  27. show()
  28. {
  29. const anims = [];
  30.  
  31. if (CABLES.UI && window.gui)
  32. {
  33. const ops = gui.corePatch().ops;
  34. for (let i = 0; i < ops.length; i++)
  35. {
  36. for (let j = 0; j < ops[i].portsIn.length; j++)
  37. {
  38. const p = ops[i].portsIn[j];
  39.  
  40. if (p.isAnimated())anims.push(
  41. {
  42. "opname": ops[i].name,
  43. "opid": ops[i].id,
  44. "portname": p.name,
  45. "colorClass": "op_color_" + defaultOps.getNamespaceClassName(ops[i].objName)
  46. });
  47. }
  48. }
  49. }
  50.  
  51. if (this.anim)
  52. {
  53. for (let i = 0; i < this.anim.keys.length; i++)
  54. {
  55. this.anim.keys[i].frame = this.anim.keys[i].time * gui.timeLine().getFPS();
  56. }
  57. }
  58.  
  59. const html = getHandleBarHtml("meta_keyframes",
  60. {
  61. "anim": this.anim,
  62. "anims": anims
  63. });
  64.  
  65. this._tab.html(html);
  66. }
  67.  
  68. showAnim(opid, portname)
  69. {
  70. CABLES.CMD.TIMELINE.showTimeline();
  71. gui.patchView.centerSelectOp(opid, true);
  72. const op = gui.corePatch().getOpById(opid);
  73. const p = op.getPort(portname);
  74.  
  75. if (p.anim) gui.timeLine().setAnim(p.anim);
  76. this.show();
  77. }
  78.  
  79.  
  80. addKey()
  81. {
  82. // const v = prompt(" []");
  83. // if (v === null) return;
  84.  
  85. new ModalDialog({
  86. "prompt": true,
  87. "title": "New Keyframe",
  88. "text": "frame value:",
  89. "promptValue": "",
  90. "promptOk": function (inputStr)
  91. {
  92. const v = inputStr;
  93.  
  94. const values = v.split(" ");
  95.  
  96. gui.timeLine().getAnim().setValue(values[0] / gui.timeLine().getFPS(), values[1] || 0);
  97. gui.timeLine().refresh();
  98. this.update();
  99. }
  100. });
  101. }
  102.  
  103. setAnim(anim)
  104. {
  105. if (!anim) return;
  106. this.anim = anim;
  107. if (userSettings.get("metatab") == "keyframes")
  108. {
  109. this.show();
  110. }
  111. }
  112. }