Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Steepfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ target :wavesync do
library 'yaml'
library 'psych'
library 'fileutils'
library 'zlib'
library 'pathname'
library 'shellwords'
library 'open3'
Expand Down
1 change: 1 addition & 0 deletions lib/wavesync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ module Wavesync
require 'wavesync/analyzer'
require 'wavesync/set'
require 'wavesync/set_editor'
require 'wavesync/octatrack_exporter'
require 'wavesync/commands'
require 'wavesync/cli'
39 changes: 37 additions & 2 deletions lib/wavesync/commands/set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ class Set < Command
self.subcommands = [
Subcommand.new(usage: 'set create NAME', description: 'Create a new track set'),
Subcommand.new(usage: 'set edit NAME', description: 'Edit an existing track set'),
Subcommand.new(usage: 'set export NAME --device DEVICE', description: 'Export a track set to a device'),
Subcommand.new(usage: 'set list', description: 'List all track sets')
].freeze

#: () -> void
def run
subcommand = ARGV.shift

_options, config = parse_options(banner: 'Usage: wavesync set <subcommand> [options]')
options, config = parse_options(banner: 'Usage: wavesync set <subcommand> [options]') do |opts, opts_hash|
opts.on('-d', '--device NAME', 'Name of device (used by export)') do |value|
opts_hash[:device] = value
end
end

case subcommand
when 'create'
Expand All @@ -43,9 +48,39 @@ def run
else
sets.each { |set| puts "#{set.name} (#{set.tracks.size} tracks)" }
end
when 'export'
name = require_name('export')
unless options[:device]
puts 'Usage: wavesync set export <name> --device <device>'
exit 1
end
device_config = config.device_configs.find { |device_config| device_config[:name] == options[:device] }
unless device_config
known = config.device_configs.map { |device_config| device_config[:name] }.join(', ')
puts "Unknown device \"#{options[:device]}\". Devices in config: #{known}"
exit 1
end
unless Wavesync::Set.exists?(config.library, name)
puts "Set '#{name}' not found. Use 'wavesync set create #{name}' to create it."
exit 1
end
unless device_config[:projects_path]
puts "Device \"#{options[:device]}\" has no 'projects_path' configured in wavesync.yml."
exit 1
end
set = Wavesync::Set.load(config.library, name)
device = Wavesync::Device.find_by(name: device_config[:model])
exporter = Wavesync::OctatrackExporter.new(set, config.library, device_config[:path], device_config[:projects_path], device: device)
if Dir.exist?(exporter.project_dir) && !Wavesync::UI.new.confirm("'#{File.basename(exporter.project_dir)}' already exists on device. Overwrite? [y/N] ")
puts 'Export cancelled.'
exit 0
end
project_path = exporter.export
puts "Exported '#{name}' to #{project_path}"
puts "#{set.tracks.size} track(s) assigned to static slots 1-#{set.tracks.size}"
else
puts "Unknown subcommand: #{subcommand || '(none)'}"
puts 'Available subcommands: create, edit, list'
puts 'Available subcommands: create, edit, export, list'
exit 1
end
end
Expand Down
15 changes: 12 additions & 3 deletions lib/wavesync/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class Config
DEFAULT_PATH = File.join(Dir.home, 'wavesync.yml')

SUPPORTED_KEYS = %w[library devices].freeze
DEVICE_SUPPORTED_KEYS = %w[name model path].freeze
DEVICE_SUPPORTED_KEYS = %w[name model path projects_path].freeze
DEVICE_REQUIRED_KEYS = %w[name model path].freeze

attr_reader :library #: String
attr_reader :device_configs #: Array[{ name: String, model: String, path: String }]
attr_reader :device_configs #: Array[{ name: String, model: String, path: String, projects_path: String? }]

#: (?String path) -> Config
def self.load(path = DEFAULT_PATH)
Expand All @@ -35,7 +35,12 @@ def initialize(data)
@library = File.expand_path(data['library'])
@device_configs = data['devices'].each_with_index.map do |device, i|
validate_device!(device, i)
{ name: device['name'], model: device['model'], path: File.expand_path(device['path']) }
{
name: device['name'],
model: device['model'],
path: File.expand_path(device['path']),
projects_path: device['projects_path'] && File.expand_path(device['projects_path'])
}
end
end

Expand Down Expand Up @@ -71,6 +76,10 @@ def validate_device!(device, index)
%w[name model path].each do |key|
raise ConfigError, "Device #{index + 1} '#{key}' must be a string" unless device[key].is_a?(String)
end

projects_path = device['projects_path']
return unless projects_path
raise ConfigError, "Device #{index + 1} 'projects_path' must be a string" unless projects_path.is_a?(String)
end
end
end
Loading
Loading