slots.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Helpers shared by the pad and sequence grids.
  2. export const BANKS = "ABCDEFGH";
  3. export const PER_BANK = 16;
  4. /** "A01" for slot 0, "B02" for slot 17. Matches Go's app.Label. */
  5. export function slotLabel(slot: number): string {
  6. const n = (slot % PER_BANK) + 1;
  7. return BANKS[Math.floor(slot / PER_BANK)] + (n < 10 ? "0" + n : String(n));
  8. }
  9. /**
  10. * The 16 slots of a bank in grid order, top-left first. Pad 1 sits
  11. * bottom-left, as on the device: the top row is pads 13-16.
  12. */
  13. export function gridSlots(bank: number): number[] {
  14. const out: number[] = [];
  15. for (let row = 3; row >= 0; row--) {
  16. for (let col = 0; col < 4; col++) {
  17. out.push(bank * PER_BANK + row * 4 + col);
  18. }
  19. }
  20. return out;
  21. }
  22. /** "+12.40" style tuning text; empty when untuned. */
  23. export function tuneText(coarse: number, fine: number): string {
  24. if (!coarse && !fine) return "";
  25. const v = coarse + fine / 100;
  26. return (v > 0 ? "+" : "") + v.toFixed(2);
  27. }
  28. /** "+5" / "-3" / "0". */
  29. export function signed(n: number): string {
  30. return (n > 0 ? "+" : "") + n;
  31. }
  32. export function bars(n: number): string {
  33. return n + (n === 1 ? " bar" : " bars");
  34. }