-
Notifications
You must be signed in to change notification settings - Fork 0
/
Transpose.js
1 lines (1 loc) · 1.94 KB
/
Transpose.js
1
function Transpose(e,s,t,a){var n,c,r=[["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],["C","Db","D","Eb","E","F","Gb","G","Ab","A","Bb","B"]],o=Iregular_Chords(s)[0],u=Iregular_Chords(t)[0];n=u.indexOf("b")>-1?1:u.indexOf("#")>-1?0:e;var l=r[e].indexOf(o),i=r[n].indexOf(u),d=Iregular_Chords(a),h=d[0],f=d[1],b=r[e].indexOf(h),p=i-l;if(0==p&&(o.indexOf("#")>-1||o.indexOf("b")>-1)&&(u.indexOf("#")>-1||u.indexOf("b")>-1))c=r[n][b]+f;else{var $=b+p;c=$>11?r[n][$-12]+f:$<0?r[n][$+12]+f:r[n][$]+f}return c}function Iregular_Chords(e){var s="",t="";return e.length>2?(subcount=1,"#"==e[1]||"b"==e[1]?(subcount++,s=e.substring(subcount),t=e.slice(0,subcount)):(s=e.substring(subcount),t=e.slice(0,subcount))):2==e.length?"#"==e[1]||"b"==e[1]?t=e:(subcount=1,s=e.substring(subcount),t=e.slice(0,subcount)):t=e,[t,s]}$(".T-chords").each(function(){$(this).text()==base_scale&&$(this).addClass("Selected-Scale")}),$(".T-chords").on("click",function(e){e.preventDefault();var s=$(this);$(".T-chords").removeClass("Selected-Scale"),s.addClass("Selected-Scale");for(var t=0,a=$(".c").text(),n=$(".chord").length,c=[],r=[],o=[],u=[],l="",i=1;i<=n;i++)$("#chord-"+i+" .c").each(function(){o=$(this).text(),l=o.replace(/\s/g,""),u=l,c.push(o),r.push(u)});t=a.indexOf("#")>-1?0:a.indexOf("b")>-1?1:0;var d=s.text(),h=[],f=0,b=[];r.forEach(function(e){b.push(Transpose(t,base_scale,d,e)),h[f++]=b}),base_scale=s.text();var p=0;for(i=0;i<h.length;i++){var g=new RegExp(r[i],"g");c[i]=c[i].replace(g,h[i]),$("#chord-"+(i+1)+" .c").each(function(){$(this).text(" "+b[p]+" "),p++})}}),$(".playpause").on("click",function(e){e.preventDefault();var s=$(this).children(".fa"),t=$(document).height();s.hasClass("fa-pause")?$("html,body").stop():$("html,body").animate({scrollTop:t},2e5,"linear"),s.toggleClass("fa-play fa-pause"),$(".body-pause").toggle()}),$(".body-pause").on("click",function(e){e.preventDefault(),$(".playpause .fa").attr("class","fa fa-play"),$("html,body").stop(),$(this).hide()});