MuseScore Dynamic Balance

Réglages pour les sons de Musescore

当前为 2025-03-09 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name MuseScore Dynamic Balance
  3. // @namespace MuseScoreEnhancements
  4. // @version 2.5
  5. // @description Réglages pour les sons de Musescore
  6. // @author Yglsan
  7. // @match *://*/*
  8. // @grant GM_addStyle
  9. // @grant GM_registerMenuCommand
  10. // @license GNU GPL 3.0
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const CONFIG = {
  17. mainGauche: {
  18. attenuation: 0.7, // Réduction de volume (0-1)
  19. rangeNotes: [48, 72], // Plage MIDI pour la main gauche (C3 à C5)
  20. fadeFinNote: 0.15 // Derniers 15% de la note en fondu
  21. },
  22. mainDroite: {
  23. boost: 1.1, // Légère amplification
  24. fadeFinNote: 0.05 // Derniers 5% en fondu
  25. },
  26. effetResonance: {
  27. attenuation: 0.85, // Réduction des harmoniques basses
  28. frequenceCoupe: 250 // Hz
  29. }
  30. };
  31.  
  32. let isActive = false;
  33. let originalNoteData = new WeakMap();
  34.  
  35. class NoteProcessor {
  36. static process(note) {
  37. if (!originalNoteData.has(note)) {
  38. originalNoteData.set(note, {
  39. velocity: note.velocity,
  40. tuning: note.tuning,
  41. timbre: note.timbre
  42. });
  43. }
  44.  
  45. const isMainGauche = this.estMainGauche(note);
  46. this.appliquerBalance(note, isMainGauche);
  47. this.appliquerFondu(note, isMainGauche);
  48. }
  49.  
  50. static estMainGauche(note) {
  51. return note.pitch >= CONFIG.mainGauche.rangeNotes[0] &&
  52. note.pitch <= CONFIG.mainGauche.rangeNotes[1];
  53. }
  54.  
  55. static appliquerBalance(note, isMainGauche) {
  56. const original = originalNoteData.get(note);
  57. if (isMainGauche) {
  58. // Atténuation progressive basée sur la vélocité originale
  59. let attenuation = CONFIG.mainGauche.attenuation;
  60. if (original.velocity < 64) attenuation += 0.15;
  61. note.velocity = Math.min(127,
  62. Math.round(original.velocity * attenuation));
  63. // Réduction des basses fréquences
  64. note.timbre = original.timbre * CONFIG.effetResonance.attenuation;
  65. note.tuning = original.tuning - 20; // Léger detune
  66. } else {
  67. note.velocity = Math.min(127,
  68. Math.round(original.velocity * CONFIG.mainDroite.boost));
  69. }
  70. }
  71.  
  72. static appliquerFondu(note, isMainGauche) {
  73. const fadePercent = isMainGauche ?
  74. CONFIG.mainGauche.fadeFinNote :
  75. CONFIG.mainDroite.fadeFinNote;
  76.  
  77. note.playbackRate = this.calculerCourbeFondu(
  78. note.duration,
  79. fadePercent
  80. );
  81. }
  82.  
  83. static calculerCourbeFondu(duration, fadePercent) {
  84. const fadeTime = duration * fadePercent;
  85. return [
  86. { time: 0, value: 1.0 },
  87. { time: duration - fadeTime, value: 1.0 },
  88. { time: duration, value: 0.3 }
  89. ];
  90. }
  91. }
  92.  
  93. function toggleEnhancements() {
  94. isActive = !isActive;
  95. const score = MuseScore.getCurrentScore();
  96. score.notes.forEach(note => {
  97. if (isActive) {
  98. NoteProcessor.process(note);
  99. } else {
  100. const original = originalNoteData.get(note);
  101. if (original) {
  102. Object.assign(note, original);
  103. }
  104. }
  105. });
  106. score.updatePlayback();
  107. updateUI();
  108. }
  109.  
  110. function createControlPanel() {
  111. const panel = document.createElement('div');
  112. panel.id = 'ms-balance-panel';
  113. panel.style.cssText = `
  114. position: fixed;
  115. top: 20px;
  116. right: 20px;
  117. background: #2c3e50;
  118. color: white;
  119. padding: 15px;
  120. border-radius: 8px;
  121. z-index: 10000;
  122. font-family: 'Arial', sans-serif;
  123. `;
  124.  
  125. panel.innerHTML = `
  126. <h3 style="margin:0 0 10px 0;">Balance Dynamique</h3>
  127. <div class="slider-container">
  128. <label>Atténuation main gauche:
  129. <input type="range" min="0.3" max="1.0" step="0.05"
  130. value="${CONFIG.mainGauche.attenuation}" id="attenuation">
  131. </label>
  132. <span id="attenuation-value">${CONFIG.mainGauche.attenuation}</span>
  133. </div>
  134. <div class="slider-container">
  135. <label>Fondu main gauche:
  136. <input type="range" min="0.05" max="0.3" step="0.01"
  137. value="${CONFIG.mainGauche.fadeFinNote}" id="fade">
  138. </label>
  139. <span id="fade-value">${CONFIG.mainGauche.fadeFinNote}</span>
  140. </div>
  141. <button id="ms-balance-toggle" style="${getButtonStyle(isActive)}">
  142. ${isActive ? 'Désactiver' : 'Activer'}
  143. </button>
  144. `;
  145.  
  146. panel.querySelector('#attenuation').addEventListener('input', e => {
  147. CONFIG.mainGauche.attenuation = parseFloat(e.target.value);
  148. panel.querySelector('#attenuation-value').textContent = e.target.value;
  149. if (isActive) toggleEnhancements();
  150. });
  151.  
  152. panel.querySelector('#fade').addEventListener('input', e => {
  153. CONFIG.mainGauche.fadeFinNote = parseFloat(e.target.value);
  154. panel.querySelector('#fade-value').textContent = e.target.value;
  155. if (isActive) toggleEnhancements();
  156. });
  157.  
  158. panel.querySelector('#ms-balance-toggle').addEventListener('click', toggleEnhancements);
  159. document.body.appendChild(panel);
  160. }
  161.  
  162.  
  163. function initialize() {
  164. if (typeof MuseScore === 'undefined') {
  165. setTimeout(initialize, 500);
  166. return;
  167. }
  168. createControlPanel();
  169. GM_registerMenuCommand('Toggle Balance', toggleEnhancements);
  170. }
  171.  
  172. GM_addStyle(`
  173. #ms-balance-panel .slider-container {
  174. margin: 10px 0;
  175. }
  176. #ms-balance-panel input[type="range"] {
  177. width: 180px;
  178. margin-top: 5px;
  179. }
  180. `);
  181.  
  182. window.addEventListener('load', initialize);
  183. })();