Вот ее код:
- Код: Выделить всё
//WSH Spectrum panel by Zin-Uru, 2010
//Version 1.0
// Use with GdiDrawText()
// {{
var DT_TOP = 0x00000000;
var DT_CENTER = 0x00000001;
var DT_VCENTER = 0x00000004;
var DT_WORDBREAK = 0x00000010;
var DT_CALCRECT = 0x00000400;
var DT_NOPREFIX = 0x00000800;
// }}
// {{
// Used in window.GetColorCUI()
ColorTypeCUI = {
text: 0,
selection_text: 1,
inactive_selection_text: 2,
background: 3,
selection_background: 4,
inactive_selection_background: 5,
active_item_frame: 6
};
// Used in window.GetFontCUI()
FontTypeCUI = {
items: 0,
labels: 1
};
// Used in window.GetColorDUI()
ColorTypeDUI = {
text: 0,
background: 1,
highlight: 2,
selection: 3
};
// Used in window.GetFontDUI()
FontTypeDUI = {
defaults: 0,
tabs: 1,
lists: 2,
playlists: 3,
statusbar: 4,
console: 5
};
//}}
//{{
// Used in window.SetCursor()
var IDC_HAND = 32649;
//}}
var track_path = fb.TitleFormat("$replace(%path%,%filename_ext%,)");
var track_fullpath = fb.TitleFormat("$if(%__referenced_file%,$if($strcmp($replace(%__referenced_file%,.$ext(%__referenced_file%),),%filename%),%path%,$replace(%path%,%filename_ext%,%__referenced_file%)),%path%)");
var track_filename = fb.TitleFormat("$if(%__referenced_file%,$if($strcmp($replace(%__referenced_file%,.$ext(%__referenced_file%),),%filename%),%filename%,$replace(%__referenced_file%,.$ext(%__referenced_file%),)),%filename%)");
var track_ext = fb.TitleFormat("$if(%__referenced_file%,$if($strcmp($replace(%__referenced_file%,.$ext(%__referenced_file%),),%filename%),$ext(%filename_ext%),$ext(%__referenced_file%)),$ext(%filename_ext%))");
var ref_ext = fb.TitleFormat("$if(%__referenced_file%,$ext(%__referenced_file%),$ext(%filename_ext%))");
var track_num = fb.TitleFormat("%track%");
var track_tf = fb.TitleFormat("%track% - %title%");
var track_filename_ext = fb.TitleFormat("%filename_ext%");
var image_name = fb.TitleFormat("$if(%__referenced_file%,$replace(%path%,%filename_ext%,%__referenced_file%))");
var image_ext = fb.TitleFormat("$if(%__referenced_file%,$ext(%__referenced_file%))");
var total = fb.TitleFormat("%totaltracks%");
var subs = fb.TitleFormat("%subsong%");
var char_quote = fb.TitleFormat("$char(34)");
var WshShell = new ActiveXObject("WScript.Shell");
var g_instancetype = window.InstanceType;
var g_font = null;
var working = 0;
var g_text;
var ww = 0, wh = 0;
var g_textcolor = 0, g_textcolor_hl = 0;
var g_backcolor = 0;
var g_hot = false;
var show_spectrum = 0;
var image;
var embed_ch;
var batch_run = 0;
//Getting properties
var work_dir = fb.FoobarPath+"\\"+window.GetProperty("WSH Spectrum folder","WSH_Spectrum\\");
var sp_height = window.GetProperty("Spectrogram height","600");
var sp_width = window.GetProperty("Spectrogram width","800");
var algo = window.GetProperty("Algorithm (1-5): Hann, Hamming, Bartlett, Rectangular or Kaiser","1");
var by_panel = window.GetProperty("Use panel size",true);
var auto_gen = window.GetProperty("Automatically generate spectrum",true);
var trans = window.GetProperty("Transparent (CUI only)",false);
var sp_algo;
algo = algo*1;
if(algo==1) sp_algo = "Hann";
if(algo==2) sp_algo = "Hamming";
if(algo==3) sp_algo = "Bartlett";
if(algo==4) sp_algo = "Rectangular";
if(algo==5) sp_algo = "Kaiser";
embed_ch = "0";
if(track_ext.Eval()!="cue" && subs.Eval()!="0" && image_ext.Eval()=="") {embed_ch = "1";}
if(track_ext.Eval()=="cue" || embed_ch=="1") {image = track_path.Eval()+"Spectrum\\track_"+track_num.Eval()+".png";} else {image = track_path.Eval()+"Spectrum\\"+ track_filename.Eval() + ".png";}
function get_font() {
if (g_instancetype == 0) { // CUI
g_font = window.GetFontCUI(FontTypeCUI.items);
} else if (g_instancetype == 1) { // DUI
g_font = window.GetFontDUI(FontTypeDUI.defaults);
} else {
// None
}
}
get_font();
function get_colors() {
if (g_instancetype == 0) { // CUI
g_textcolor = window.GetColorCUI(ColorTypeCUI.text);
g_textcolor_hl = window.GetColorCUI(ColorTypeCUI.text);
if(trans) {g_backcolor = 7;} else {g_backcolor = window.GetColorCUI(ColorTypeCUI.background);}
} else if (g_instancetype == 1) { // DUI
g_textcolor = window.GetColorDUI(ColorTypeDUI.text);
g_textcolor_hl = window.GetColorDUI(ColorTypeDUI.highlight);
g_backcolor = window.GetColorDUI(ColorTypeDUI.background);
} else {
// None
}
}
get_colors();
// START
function on_size() {
ww = window.Width;
wh = window.Height;
}
function on_paint(gr) {
var text_color = g_hot ? g_textcolor_hl : g_textcolor;
gr.FillSolidRect(0, 0, ww, wh, g_backcolor);
if(working==1) {g_text = "Generating spectrogram...";} else {g_text = "Click here to show (generate) or hide spectrogram";}
if(file_exists(image) && show_spectrum==1) {
gr.DrawImage(gdi.Image(image),0,0,window.Width,window.Height,0,0,gdi.Image(image).Width,gdi.Image(image).Height,0,255);
} else {
gr.GdiDrawText(g_text, g_font, text_color, 0, 0, ww, wh, DT_VCENTER | DT_CENTER | DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
}
}
function on_mouse_lbtn_up(x, y) {
if(track_path.Eval().substring(0,4)=="cdda" || ref_ext.Eval()=="avi" || ref_ext.Eval()=="mpg" || ref_ext.Eval()=="mp4" || ref_ext.Eval()=="mkv" || ref_ext.Eval()=="wmv" || ref_ext.Eval()=="tak") {
} else {
if(show_spectrum==0) {
show_spectrum = 1;
if(working==0 && fb.IsPlaying) {
if(file_exists(image)==false) {create_batch(track_ext.Eval()); batch_run = 1;}
working = 1;
}
} else {
if(batch_run==0) {
show_spectrum = 0;
working = 0;
}
}
window.Repaint();
}
}
function on_mouse_move() {
if (!g_hot) {
window.SetCursor(IDC_HAND);
g_hot = true;
window.Repaint();
}
}
function on_mouse_leave() {
if (g_hot) {
g_hot = false;
window.Repaint();
}
}
function on_font_changed() {
get_font();
window.Repaint();
}
function on_colors_changed() {
get_colors();
window.Repaint();
}
function file_exists(chemin) {
var fso, bool;
fso = new ActiveXObject("Scripting.FileSystemObject");
bool=fso.Fileexists(chemin);
return bool;
}
function GrabShortPath(filespec)
{
var fso, f, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
if(filespec && track_path.Eval().substring(0,4)!="cdda") {
f = fso.GetFile(filespec);
s = f.ShortPath;
} else {s = "";}
return(s);
}
function GrabShortName(filespec)
{
var fso, f, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
if(filespec && track_path.Eval().substring(0,4)!="cdda") {
f = fso.GetFile(filespec);
s = f.ShortName
} else {s = "";}
return(s);
}
function on_playback_time(time) {
if(file_exists(image) && working==1) {
working = 0;
batch_run = 0;
window.Repaint();
}
}
function on_playback_new_track(info) {
CollectGarbage();
embed_ch = "0";
if(track_ext.Eval()!="cue" && subs.Eval()!="0" && image_ext.Eval()=="") {embed_ch = "1";}
if(track_ext.Eval()=="cue" || embed_ch=="1") {image = track_path.Eval()+"Spectrum\\track_"+track_num.Eval()+".png";} else {image = track_path.Eval()+"Spectrum\\"+ track_filename.Eval() + ".png";}
if(file_exists(image)==false) {
if(auto_gen) {
if(track_path.Eval().substring(0,4)=="cdda" || ref_ext.Eval()=="avi" || ref_ext.Eval()=="mpg" || ref_ext.Eval()=="mp4" || ref_ext.Eval()=="mkv" || ref_ext.Eval()=="wmv" || ref_ext.Eval()=="tak") {
} else {
create_batch(track_ext.Eval());
batch_run = 1;
working = 1;
show_spectrum = 1;
}
} else {
show_spectrum = 0; working = 0;
}
} else {
show_spectrum = 1;
}
window.Repaint();
}
function convert_to_translit(str) {
var work_str = str;
var alphabet1 = "абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ";
var alphabet2 = "abvgdeegziiklmnoprstyfxc4wwbu'euaABVGDEEGZIIKLMNOPRSTYFXC4WWbU'EUA";
for(var i = 0; i < work_str.length; i++) {
for(var j = 0; j < alphabet1.length; j++) {
if(work_str.charAt(i)==alphabet1.charAt(j)) {
work_str = work_str.substring(0,i)+alphabet2.charAt(j)+work_str.substring(i+1,work_str.length);
break;
}
}
}
return work_str;
}
function create_batch(ftype) {
var fso, f1, ts, s;
var ForReading = 1;
var ForWriting = 2;
var Str0, Str1, Str2, Str3, Str4;
var chem;
var mypath;
var mover;
var dest;
var num;
var imgn;
var imgx;
var tot;
var ext;
var pic_text;
var s_trk_fullpath = GrabShortPath(track_fullpath.Eval());
var s_trk_filename_ext = GrabShortName(track_fullpath.Eval());
var wtitle="WSH Spectrum";
var runcmd;
var c_quote;
if(by_panel) {
sp_height = window.Height-50;
sp_width = window.Width+10;
}
if(sp_height<130) sp_height = 130;
if(sp_width<100) sp_width = 100;
cdda_check = track_path.Eval();
ext = ref_ext.Eval();
if(cdda_check.substring(0,4)=="cdda" || ext=="avi" || ext=="mpg" || ext=="mp4" || ext=="mkv" || ext=="wmv" || ext=="tak" || s_trk_fullpath=="") {
} else {
c_quote = char_quote.Eval();
chem = track_path.Eval();
mypath = s_trk_fullpath.substring(0,s_trk_fullpath.length-s_trk_filename_ext.length);
num = track_num.Eval();
dest = "\\" + track_filename.Eval() + ".png";
imgn = image_name.Eval();
imgx = image_ext.Eval();
ext = track_ext.Eval();
tot = total.Eval();
fso = new ActiveXObject("Scripting.FileSystemObject");
if (file_exists(work_dir + "WSH_Spectrum.bat")==true) {
ts = fso.OpenTextFile(work_dir + "WSH_Spectrum.bat", ForWriting);
} else {
ts = fso.CreateTextFile(work_dir + "WSH_Spectrum.bat", ForWriting);
}
ts.WriteLine("@echo off");
Str4=s_trk_fullpath;
Str3=s_trk_fullpath;
//extract embedded cue
if(embed_ch=="1") {
Str4=s_trk_fullpath.substring(0,s_trk_fullpath.length-s_trk_filename_ext.length)+"tmp.cue";
ts.WriteLine(GrabShortPath(work_dir+"tag.exe")+" --tocuen "+Str4+" "+s_trk_fullpath);
imgn=track_fullpath.Eval();
imgx=ext;
}
if(ftype=="cue" || embed_ch=="1") {
pic_text="'"+track_tf.Eval()+"' of "+track_filename_ext.Eval();
image = chem+"\\Spectrum\\track_"+num+".png";
} else {
pic_text=track_filename_ext.Eval();
image = chem+"\\Spectrum\\"+ track_filename.Eval() + ".png";
}
pic_text = convert_to_translit(pic_text);
//generate spectrum picture for track
if(ftype=="wav") {
ts.WriteLine(GrabShortPath(work_dir+"SOX\\sox.exe")+" "+s_trk_fullpath+" -n spectrogram -x "+sp_width+" -Y "+sp_height+" -w "+sp_algo+" -S 0 -t "+pic_text+' -c "Generated with SOX in Foobar2000 WSH Spectrum panel" -o '+mypath+"tmp.png");
ts.WriteLine("goto final");
} else {
Str0 = GrabShortPath(work_dir+"shntool.exe");
Str1 = GrabShortPath(work_dir+"ffmpeg.exe");
Str2 = GrabShortPath(work_dir+"SOX\\sox.exe");
if(ftype=="cue" || embed_ch=="1") {
s_imgn = GrabShortPath(imgn);
Str3 = mypath+"track_"+num+".wav";
ts.WriteLine(Str1+" -i "+s_imgn+" "+s_imgn.substring(0,s_imgn.length-imgx.length-1)+".wav");
if(tot=="01") {
ts.WriteLine(Str1+" -i "+s_imgn+" "+mypath+"track_"+num+".wav");
} else {
ts.WriteLine(Str0+" split "+s_imgn.substring(0,s_imgn.length-imgx.length-1)+".wav -f "+Str4+" -O always -o wav -a track_ -d "+mypath+" -x "+num);
//fix for not null pregap of the first track
ts.WriteLine("if exist "+mypath+"track_"+num+".wav goto next");
ts.WriteLine("del "+mypath+"track_*.wav");
ts.WriteLine(Str0+" split "+s_imgn.substring(0,s_imgn.length-imgx.length-1)+".wav -f "+Str4+" -O always -o wav -a track_ -d "+mypath+" -x "+(num*1+1));
ts.WriteLine(":next");
}
if(embed_ch==1) {ts.WriteLine("if exist "+Str4+" del "+Str4);}
ts.WriteLine("del "+s_imgn.substring(0,s_imgn.length-imgx.length-1)+".wav");
dest = "\\track_"+num+".png";
} else {
if(ftype.length==4) {
Str3 = s_trk_fullpath.substring(0,s_trk_fullpath.length-ext.length-0)+".wav";
} else {
Str3 = s_trk_fullpath.substring(0,s_trk_fullpath.length-ext.length-1)+".wav";
}
ts.WriteLine(Str1+" -i "+s_trk_fullpath+" "+Str3);
}
ts.WriteLine(Str2+" "+Str3+" -n spectrogram -x "+sp_width+" -Y "+sp_height+" -w "+sp_algo+' -S 0 -t "'+pic_text+'" -c "Generated with SOX in Foobar2000 WSH Spectrum panel" -o "'+mypath+'tmp.png"');
ts.WriteLine("del "+Str3);
ts.WriteLine("goto final");
}
//finalizing process
ts.WriteLine(":final");
ts.WriteLine("if not exist "+mypath+"Spectrum"+" md "+mypath+"Spectrum");
ts.WriteLine("move "+mypath + 'tmp.png "'+mypath+"Spectrum"+dest+'"');
// ts.WriteLine("pause");
ts.WriteLine("del "+"%0");
ts.WriteLine("exit");
ts.Close();
runcmd = "START "+c_quote+wtitle+c_quote+" /MIN cmd /C ";
WshShell.run("cmd /C "+runcmd+GrabShortPath(work_dir+"WSH_Spectrum.bat"));
}
}
Changelog:
- Код: Выделить всё
29.04.2010 - Версия 1.0:
- Решена проблема с русскими именами файлов (заменяются на транслит при выводе).
16.04.2010 - Версия 0.92:
- Релиз.
Разпознается большинство типов файлов, а также image+.cue (имена файла-образа и .cue должны совпадать), tracks+.cue и image with embedded cue.
Для работы панельки необходимо несколько утилит, вот архив с ними: ССЫЛКА.
Использовать так:
1. Кидаем папку WSH_Spectrum из архива в папку Фубара.
2. Убеждаемся, что отключена галочка File -> Preferences -> Tools -> WSH Panel Mod -> Safe mode.
3. Добавляем WSH-панель в ваш конфиг.
4. Импортируем в панель скрипт из файла WSH_Spectrum.txt, лежащего в архиве (ПКМ -> Configure -> Import).
5. Настраиваем панельку по ПКМ -> Properties:
- выбираем алгоритм генерации спектра;
- задаем примерную ширину и высоту получаемых картинок;
- выбираем тип определения ширины и высоты - из заданных значений, либо из текущих размеров панели;
- выбираем, автоматически ли будут генерироваться спектры;
- ставим если нужно для панели прозрачность Transparent (CUI only), затем в ПКМ -> Configure -> Pseudo Transparent.
Прошу пробовать, если появятся предложения или найдутся какие-то баги, пожалуйста, отписывайтесь. ;)