subcmd

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2017 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Dump = cli.Command{
	Name:      "dump",
	Aliases:   []string{"d"},
	Usage:     "Dumps SMAF format files (.mmf|.spf|.vma|.vm3|.vm5)",
	ArgsUsage: "<filename>",
	Flags: []cli.Flag{
		cli.BoolFlag{
			Name:  "json, j",
			Usage: `Dumps in JSON format`,
		},
		cli.BoolFlag{
			Name:  "voice, v",
			Usage: `Dumps voice data only`,
		},
		cli.BoolFlag{
			Name:  "exclusive, x",
			Usage: `Dumps exclusives only`,
		},
		cli.BoolFlag{
			Name:  "debug, d",
			Usage: `Show debug messages`,
		},
		cli.BoolFlag{
			Name:  "quiet, q",
			Usage: `Suppress information messages`,
		},
		cli.BoolFlag{
			Name:  "silent, Q",
			Usage: `Do not output any messages`,
		},
	},
	Action: func(ctx *cli.Context) error {
		if ctx.NArg() < 1 {
			cli.ShowCommandHelp(ctx, "dump")
			os.Exit(1)
		}
		if ctx.Bool("debug") {
			log.Level = log.LogLevel_Debug
		} else if ctx.Bool("silent") {
			log.Level = log.LogLevel_None
		} else if ctx.Bool("quiet") {
			log.Level = log.LogLevel_Warn
		}
		file := ctx.Args()[0]
		ext := ""
		i := len(file) - 4
		if 0 <= i {
			ext = strings.ToLower(file[i:])
		}
		var data fmt.Stringer
		var err error
		switch ext {
		case ".mmf", ".spf":
			fc, err := chunk.NewFileChunk(file)
			data = fc
			if err == nil && (ctx.Bool("voice") || ctx.Bool("exclusive")) {
				exclusives := fc.CollectExclusives()
				data = exclusives
				if ctx.Bool("voice") {
					data = exclusives.Voices()
				}
			}
		case ".vma":
			data, err = voice.NewVMAVoiceLib(file)
		case ".vm3":
			data, err = voice.NewVM3VoiceLib(file)
		case ".vm5":
			data, err = voice.NewVM5VoiceLib(file)
		default:
			return cli.NewExitError(fmt.Errorf("Unknown file extension"), 1)
		}
		if err != nil {
			switch data.(type) {
			case nil:
				return cli.NewExitError(err, 1)
			default:
				log.Warnf(err.Error())
			}
		}
		if ctx.Bool("json") {
			j, err := json.MarshalIndent(data, "", "  ")
			if err != nil {
				return cli.NewExitError(err, 1)
			}
			fmt.Println(string(j))
		} else {
			fmt.Println(data.String())
		}
		return nil
	},
}
View Source
var Play = cli.Command{
	Name:      "play",
	Aliases:   []string{"p"},
	Usage:     "Plays SMAF format files (.mmf|.spf)",
	ArgsUsage: "<device> <filename>",
	Flags: []cli.Flag{
		cli.BoolFlag{
			Name:  "state, s",
			Usage: `Show state`,
		},
		cli.IntFlag{
			Name:  "volume, v",
			Usage: `Master volume (0..63)`,
			Value: 48,
		},
		cli.IntFlag{
			Name:  "gain, g",
			Usage: `Analog gain (0..3)`,
			Value: 1,
		},
		cli.IntFlag{
			Name:  "seqvol, V",
			Usage: `SeqVol (0..31)`,
			Value: 16,
		},
		cli.IntFlag{
			Name:  "loop, l",
			Usage: `Loop count (0: infinite)`,
			Value: 1,
		},
		cli.IntFlag{
			Name:  "baudrate, r",
			Usage: `Baud rate ` + serial.BaudRateList(),
			Value: 57600,
		},
		cli.BoolFlag{
			Name:  "debug, d",
			Usage: `Show debug messages`,
		},
		cli.BoolFlag{
			Name:  "quiet, q",
			Usage: `Suppress information messages`,
		},
		cli.BoolFlag{
			Name:  "silent, Q",
			Usage: `Do not output any messages`,
		},
	},
	Action: func(ctx *cli.Context) error {
		if ctx.NArg() < 2 || ctx.Int("loop") < 0 ||
			ctx.Int("volume") < 0 || 63 < ctx.Int("volume") ||
			ctx.Int("gain") < 0 || 3 < ctx.Int("gain") ||
			ctx.Int("seqvol") < 0 || 31 < ctx.Int("seqvol") ||
			!serial.IsValidBaudRate(ctx.Int("baudrate")) {
			cli.ShowCommandHelp(ctx, "play")
			os.Exit(1)
		}
		if ctx.Bool("debug") {
			log.Level = log.LogLevel_Debug
		} else if ctx.Bool("silent") {
			log.Level = log.LogLevel_None
		} else if ctx.Bool("quiet") {
			log.Level = log.LogLevel_Warn
		}
		args := ctx.Args()
		mmf, err := chunk.NewFileChunk(args[1])
		if err != nil {
			return cli.NewExitError(err, 1)
		}
		q := sequencer.Sequencer{
			DeviceName: args[0],
			ShowState:  ctx.Bool("state"),
		}
		opts := &sequencer.SequencerOptions{
			Loop:     ctx.Int("loop"),
			Volume:   ctx.Int("volume"),
			Gain:     ctx.Int("gain"),
			SeqVol:   ctx.Int("seqvol"),
			BaudRate: ctx.Int("baudrate"),
		}
		err = q.Play(mmf, opts)
		if err != nil {
			return cli.NewExitError(err, 1)
		}
		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL