溯惘逐忆
- UID
- 5006
- 主题
- 帖子
- 经验
- 点
- 棉棒
- 根
- 人气
- 点
- 在线时间
- 小时
- 最后登录
- 1970-1-1
|
本帖最后由 mizuku 于 2019-12-11 14:02 编辑
想着,平时可能欲火焚身的时候想快速听一个音声里想听的地方,有没有办法做个标记呢,很多readme文件里面会提示相关的Play的时间点,但是还要打开看readme,太麻烦了
于是,就去学了学js,在foobar2000的WSH mod Plus里写了一个demo.
写到一半,才发现已经2006年就有相关的组件了,脸一黑(以前好像还用过,但是官网撤下了这个插件,后来忘了)
组件在这里:
https://hydrogenaud.io/index.php?topic=46612.0 (似乎中国ip被禁了,需要fq)
https://www.dlldown.co/F/2013/05 ... arks_dll_24503.html (应该不需要fq)
这东西是真的不错,不仅能记住位置,还能记住playlist,音量.双击就可以自动打开文件并播放相应的位置
但正是如此,所以采取了把所有信息记录在单独的数据文件里面,并且文件位置改变相应的书签就会失效
这和我的设想还是不一样的,我单纯想把信息记录在文件的tag里面,包括书签名称,时间,注释. 缺点就是必须先播放这个文件,才能使用书签
目前只写了基础的功能,只能标记时间,并且没有滚动条,有相关安装经验的同学可以试试,仅仅是一个想法而已,直接作废怪可惜的:- // Use with GdiDrawText()
- // {{
- DT_TOP = 0x00000000;
- DT_LEFT = 0x00000000;
- DT_CENTER = 0x00000001;
- DT_RIGHT = 0x00000002;
- DT_VCENTER = 0x00000004;
- DT_BOTTOM = 0x00000008;
- DT_WORDBREAK = 0x00000010;
- DT_SINGLELINE = 0x00000020;
- DT_EXPANDTABS = 0x00000040;
- DT_TABSTOP = 0x00000080;
- DT_NOCLIP = 0x00000100;
- DT_EXTERNALLEADING = 0x00000200;
- DT_CALCRECT = 0x00000400; // [1.2.1] Handles well
- DT_NOPREFIX = 0x00000800; // NOTE: Please use this flag, or a '&' character will become an underline '_'
- DT_INTERNAL = 0x00001000;
- DT_EDITCONTROL = 0x00002000;
- DT_PATH_ELLIPSIS = 0x00004000;
- DT_END_ELLIPSIS = 0x00008000;
- DT_MODIFYSTRING = 0x00010000; // do not use
- DT_RTLREADING = 0x00020000;
- DT_WORD_ELLIPSIS = 0x00040000;
- DT_NOFULLWIDTHCHARBREAK = 0x00080000;
- DT_HIDEPREFIX = 0x00100000;
- DT_PREFIXONLY = 0x00200000;
- var MF_SEPARATOR = 0x00000800;
- var MF_ENABLED = 0x00000000;
- var MF_GRAYED = 0x00000001;
- var MF_DISABLED = 0x00000002;
- var MF_UNCHECKED = 0x00000000;
- var MF_CHECKED = 0x00000008;
- var MF_STRING = 0x00000000;
- var MF_POPUP = 0x00000010;
- var MF_RIGHTJUSTIFY = 0x00004000;
- VK_SHIFT = 0x10;
- // ================================================================================= //
- var safeMode = false;
- try {
- WshShell = new ActiveXObject("WScript.Shell");
- doc = new ActiveXObject("htmlfile");
- } catch (e) {
- fb.trace("----------------------------------------------------------------------");
- fb.trace(e + "\nFix: Disable safe mode in Preferences > Tools > WSH Panel Mod");
- fb.trace("----------------------------------------------------------------------");
- safeMode = true;
- }
- // ================================================================================= //
- function print(msg) {
- fb.trace("---> " + msg);
- }
- function $(field, metadb) {
- var tf;
- try {
- tf = fb.TitleFormat(field).EvalWithMetadb(metadb);
- } catch (e) {
- tf = e + " (Invalid metadb!)"
- };
- return tf;
- }
- var g_textcolor = RGB(100,100,100);
- var g_backcolor = RGB(200,200,200);
- var g_font = gdi.Font("Tahoma", 12)
- var g_select_txt_col;
- var g_select_bg_col;
- function TimeFmt(t) {
- var zpad = function (n) {
- var str = n.toString();
- return (str.length < 2) ? "0" + str : str;
- }
- var h = Math.floor(t / 3600);
- t -= h * 3600;
- var m = Math.floor(t / 60);
- t -= m * 60;
- var s = Math.floor(t);
- if (h > 0)
- return h.toString() + ":" + zpad(m) + ":" + zpad(s);
- return m.toString() + ":" + zpad(s);
- }
- function toRGB(d) { // convert back to RGB values
- var d = d - 0xff000000;
- var r = d >> 16;
- var g = d >> 8 & 0xFF;
- var b = d & 0xFF;
- return [r, g, b];
- }
- function blendColors(c1, c2, factor) {
- // When factor is 0, result is 100% color1, when factor is 1, result is 100% color2.
- var c1 = toRGB(c1);
- var c2 = toRGB(c2);
- var r = Math.round(c1[0] + factor * (c2[0] - c1[0]));
- var g = Math.round(c1[1] + factor * (c2[1] - c1[1]));
- var b = Math.round(c1[2] + factor * (c2[2] - c1[2]));
- //fb.trace("R = " + r + " G = " + g + " B = " + b);
- return (0xff000000 | (r << 16) | (g << 8) | (b));
- }
- function setAlpha(color, a) {
- return ((color & 0x00ffffff) | (a << 24));
- }
- function RGBA(r, g, b, a) {
- return ((a << 24) | (r << 16) | (g << 8) | (b));
- }
- function RGB(r, g, b) {
- return (0xff000000 | (r << 16) | (g << 8) | (b));
- }
- ////////////////////////////// common.js END //////////////////////////////////////
- ButtonStates = {
- normal : 0,
- hover : 1,
- down : 2
- };
- var g_textcolor_2 = RGB(11,11,11);
- var row = 20 // 每一记录的行高
- var ww = window.Width;
- var wh = window.Height;
- var g_metadb = null;
- var g_tabs = [];
- function metaFind(info, name) {
- for (var i = 0; i < info.MetaCount; i++) {
- if (info.MetaName(i).toLowerCase() == name.toLowerCase())
- return i;
- }
-
- return -1;
- }
- function metaGet(info, name) {
- var i = metaFind(info, name);
- var arr = []
- if (i != -1) {
- for (var j = 0; j < info.MetaValueCount(i); j++) {
- arr.push(info.MetaValue(i, j));
- }
- }
-
- return arr;
- }
- function updateGTabs(){ //update g_tabs统一从这个函数
- metadb = fb.getNowPlaying();
- var arr = metaGet(metadb.GetFileInfo(),"DOUMRK");
- var i;
- g_tabs = [];
- for(i=0;i<arr.length;i++){
- g_tabs.push(new tab(TimeFmt(parseInt(arr[i]))));
- }
- }
- function string2time(s){
- var a = s.split(':')
- var total = 0;
- var i;
- for(i=0;i<a.length;i++){
- total = total*60+parseInt(a[i]);
- }
- return total;
- }
- function list_menu(x,y,idx){
- var _menu = window.CreatePopupMenu();
-
- if(idx == -1) {
- // add new
- _menu.AppendMenuItem(MF_STRING, 100, "add new");
- }
- else{
- _menu.AppendMenuItem(MF_STRING, 200, "remove");
- _menu.AppendMenuItem(MF_STRING, 201, "clearall");
- }
- var ret;
- ret = _menu.TrackPopupMenu(x, y);
- var metadb = fb.getNowPlaying();
- switch(ret){
- case(100):
- var mark_time = String(Math.round(fb.PlaybackTime,0));
-
- if(metadb&&mark_time!=='0'){
- var arr = metaGet(metadb.GetFileInfo(),"DOUMRK");
- arr.push(mark_time);
- metadb.UpdateFileInfoSimple("DOUMRK",arr.join(';'),"DOUMRK");
- // 很奇怪,应该有更好的何时同步的做法
- g_tabs.push(new tab(TimeFmt(parseInt(mark_time))));
- // updateGTabs();
- window.repaint();
- }
- break;
- case(200):
- g_tabs.splice(idx,1);
- var arr = get_mark_from_g_tabs();
- if(arr.length > 0){
- metadb.UpdateFileInfoSimple("DOUMRK",arr.join(';'),"DOUMRK");
- }
- window.repaint();
- break;
- case(201):
- g_tabs = [];
- metadb.UpdateFileInfoSimple("DOUMRK","");
- window.repaint();
- break;
- }
- _menu.Dispose();
-
- }
- function get_mark_from_g_tabs(){
- var i;
- var arr = [];
- for(i=0;i<g_tabs.length;i++){
- arr.push(g_tabs[i].str);
- }
- return arr;
- }
- function indexOf2(array,item){
- var i = 0;
- for(i=0;i<array.length;i++){
- if(array[i] === item){break;}
- }
- if(i===array.length){i = -1;}
- return i
- }
- tab = function (str) {
- this.w,
- this.h = 0;
- this.str = str;
- this.state = ButtonStates.normal;
- this.Font = gdi.Font("Segoe UI", 14);
- this.update = function (active) {
- this.active = active;
- this.repaint();
- }
- // this.btn = new button(clear_off,clear_ov,clear_on);
-
- this.draw = function (gr, x, y) {
- this.x = x;
- this.y = y;
- this.w = ww;
- this.h = row;
-
- gr.FillSolidRect(this.x, this.y, this.w, this.h, this.state == ButtonStates.hover ? blendColors(g_textcolor, g_backcolor, 0.94) : this.state == ButtonStates.down ? blendColors(g_textcolor, g_backcolor, 0.94) : this.active ? setAlpha(g_textcolor_2, 30) : 0);
- gr.GdiDrawText(this.str, this.Font, g_textcolor_2, this.x + 20, this.y, this.w - 24, this.h, DT_LEFT | DT_CALCRECT | DT_VCENTER | DT_END_ELLIPSIS | DT_NOPREFIX);
-
- // this.btn.draw(gr,this.x+this.w-this.btn.w*2,this.y,255);
- }
- this.display_context_menu = function (x, y, id) {};
- this.repaint = function () {
- window.RepaintRect(this.x, this.y, this.w, this.h);
- }
- this.isXYok = function(x,y){
- return (x > this.x && x < this.x+this.w && y > this.y && y < this.y + this.h);
- }
- this.checkstate = function (event, x, y) {
- // 如何解决
- this.ishover = (x > this.x && x < this.x+this.w && y > this.y && y < this.y + this.h);
- this.old = this.state;
-
- // var btn_state = this.btn.checkstate(event,x,y);
-
- switch (event) {
- case "down":
- switch (this.state) {
- case ButtonStates.normal:
- case ButtonStates.hover:
- this.state = this.ishover ? ButtonStates.down : ButtonStates.normal;
- break;
- };
- break;
- case "up":
- this.state = this.ishover ? ButtonStates.hover : ButtonStates.normal;
-
- break;
- case "right":
- if (this.ishover)
- this.display_context_menu(x, y, id);
- break;
- case "move":
- switch (this.state) {
- case ButtonStates.normal:
- case ButtonStates.hover:
- this.state = this.ishover ? ButtonStates.hover : ButtonStates.normal;
- break;
- };
- break;
- case "leave":
- this.state = this.isdown ? ButtonStates.down : ButtonStates.normal;
- break;
- }
- if (this.state != this.old)
- this.repaint();
- return this.state;
- }
- }
- // callback starts -->
- function on_mouse_move(x, y) {
- var i = 0;
- for(i=0;i<g_tabs.length;i++){
- g_tabs[i].checkstate("move",x,y);
- }
- }
- function on_mouse_leave(x,y){
- var i;
- for(i=0;i<g_tabs.length;i++){
- g_tabs[i].checkstate("leave",0,0);
- }
- }
- function on_mouse_lbtn_down(x, y, mask) {
- var i;
- for(i=0;i<g_tabs.length;i++){
- g_tabs[i].checkstate("down",x,y);
- }
- }
- function on_mouse_lbtn_up(x, y, mask) {
- var i;
- for(i=0;i<g_tabs.length;i++){
- if(g_tabs[i].checkstate("up",x,y)==ButtonStates.hover){
- fb.PlaybackTime = string2time(g_tabs[i].str)
- }
- }
- }
- function on_mouse_rbtn_down(x,y){
- rbtnDown = true;
- }
- function on_mouse_rbtn_up(x,y){
-
- var idx = -1;
- if(rbtnDown){
- if (utils.IsKeyPressed(VK_SHIFT)){
- return false;
- }else{
- var k = 0;
- for(k=0;k<g_tabs.length;k++){
- if(g_tabs[k].isXYok(x,y)){
- idx = k;
- }
- }
- list_menu(x,y,idx);
- return true;
- }
- }
- return true;
- }
- function on_paint(gr){
- var i;
- for(i=0;i<g_tabs.length;i++){
- g_tabs[i].draw(gr,20,20+20*i);
- }
- }
- function on_playback_new_track(metadb){
- g_metadb = metadb;
- updateGTabs();
- window.repaint();
- }
- function on_size() {
- ww = window.Width;
- hh = window.Height;
- }
- // <-- callback ends
复制代码
|
|