How to use music-gamut - 10 common examples

To help you get started, we’ve selected a few music-gamut examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tonaljs / tonal / packages / music-scale / lib / select.js View on Github external
return G.operation(function (g) {
    var nums = G.split(pttn).map(function (n) { return +n - 1 })
    var index = []
    build(g, false).forEach(function (item) {
      var fifths = (item[0] + 1) % 7
      index[STEPS[fifths]] = item
    })
    var selected = nums.map(function (n) {
      var i = index[n % 7]
      // up an octave if number > 7
      if (i && n > 6) {
        i = i.slice()
        i[1] = i[1] + Math.floor(n / 7)
      }
      return i
    })
    return selected.map(transpose(g[0]))
  })
github tonaljs / tonal / packages / music-scale / lib / select.js View on Github external
module.exports = function select (pttn, notes) {
  if (arguments.length === 2) return select(pttn)(notes)

  return G.operation(function (g) {
    var nums = G.split(pttn).map(function (n) { return +n - 1 })
    var index = []
    build(g, false).forEach(function (item) {
      var fifths = (item[0] + 1) % 7
      index[STEPS[fifths]] = item
    })
    var selected = nums.map(function (n) {
      var i = index[n % 7]
      // up an octave if number > 7
      if (i && n > 6) {
        i = i.slice()
        i[1] = i[1] + Math.floor(n / 7)
      }
      return i
    })
    return selected.map(transpose(g[0]))
github tonaljs / tonal / packages / note-filter / index.js View on Github external
function notesFilter (notes) {
  var fns = gamut.split(notes).map(parse).map(noteFilter)
  var len = fns.length
  return function (note) {
    for (var i = 0; i < len; i++) {
      if (fns[i](note)) return true
    }
    return false
  }
}
github tonaljs / tonal / packages / note-filter / index.js View on Github external
filter.midi = function (fn, midi) {
  if (arguments.length === 1) return function (m) { return filter.midi(fn, m) }
  fn = filterFn(fn)
  var midiNotes = gamut.split(midi).map(note)
  return gamut.reduce(function (notes, n) {
    if (fn(n)) notes.push(n)
    else if (fn(prevEnh(n))) notes.push(prevEnh(n))
    else if (fn(nextEnh(n))) notes.push(nextEnh(n))
    return notes
  }, [], midiNotes)
}
github tonaljs / tonal / packages / note-filter / index.js View on Github external
filter.midi = function (fn, midi) {
  if (arguments.length === 1) return function (m) { return filter.midi(fn, m) }
  fn = filterFn(fn)
  var midiNotes = gamut.split(midi).map(note)
  return gamut.reduce(function (notes, n) {
    if (fn(n)) notes.push(n)
    else if (fn(prevEnh(n))) notes.push(prevEnh(n))
    else if (fn(nextEnh(n))) notes.push(nextEnh(n))
    return notes
  }, [], midiNotes)
}
github tonaljs / tonal / packages / note-harmonizer / index.js View on Github external
function harmonize (source, tonic) {
  if (arguments.length === 1) return function (t) { return harmonize(source, t) }
  return gamut.transform(function (g) {
    if (tonic === null) return g
    var base = g[0]
    var intervals = g.map(distanceTo(base))
    if (tonic === false) return intervals
    tonic = parse(tonic)
    return intervals.map(transpose(tonic))
  }, source)
}
github tonaljs / tonal / packages / chord-progression / index.js View on Github external
module.exports = function (tonic, progression) {
  return gamut.transform(false, progression)
    .map(function (e) { return roman.exec(e) })
    .map(function (roman) {
      if (!roman) return null
      var intervl = parse(roman[2])
      return transpose(tonic, intervl) + roman[3]
    })
}
github tonaljs / tonal / packages / pitch-sort / index.js View on Github external
function sort (comp, source) {
  if (arguments.length > 1) return sort(comp)(source)
  if (comp === null || comp === true) comp = asc
  else if (comp === false) comp = desc
  return transform(function (g) { return g.sort(comp) })
}
github tonaljs / tonal / packages / note-filter / index.js View on Github external
function filter (fn, notes) {
  if (arguments.length > 1) return filter(fn)(notes)
  fn = filterFn(fn)
  return gamut.filter(fn)
}
github danigb / music-chord / dictionary.js View on Github external
function intervals (src) { return gamut.sortBySize(gamut.distances(null, src)) }