コード例 #1
0
        private void SaveButtonListener()
        {
            var ccDef = new NoteRowDef();

            ccDef.SetNote(new Note(View.NoteDropdown.value, View.OctaveDropdown.value));
            ccDef.SetLabel(View.NameInput.text);
            ccDef.SetAlwaysShow(View.AlwaysShowToggle.isOn);

            AddNoteRowSignal.Dispatch(ccDef);
            ResetValues();
        }
コード例 #2
0
        public List <InstrumentDef> ParseInstruments(string content)
        {
            var           instruments = new List <InstrumentDef>();
            InstrumentDef instrument  = null;
            var           lines       = content.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            var           i           = 0;

            while (i < lines.Length - 1)
            {
                string name;
                string value;

                if (!ParseLine(lines[i++], out name, out value))
                {
                    Debug.LogError($"<color=\"aqua\">PyramidInstrumentsParser.ParseInstruments() : Invalid line({i}) : {lines[i]}</color>");
                    return(null);
                }

                if (name == NAME)
                {
                    //new instrument
                    instrument      = new InstrumentDef();
                    instrument.Name = value;

                    //Midi Port
                    ParseLine(lines[i++], out name, out value); //TODO check ParseLine return value
                    if (name != OUT)
                    {
                        Debug.LogError($"<color=\"aqua\">PyramidInstrumentsParser.ParseInstruments() : Instrument OUT expected on line({i}) : {lines[i]}</color>");
                    }

                    instrument.MidiPort = value == "A" ? 1 : 2;

                    //Midi Channel
                    ParseLine(lines[i++], out name, out value); //TODO check ParseLine return value
                    if (name != CHANNEL)
                    {
                        Debug.LogError($"<color=\"aqua\">PyramidInstrumentsParser.ParseInstruments() : Instrument CHANNEL expected on line({i}) : {lines[i]}</color>");
                    }

                    instrument.MidiChannel = int.Parse(value);

                    //Add to collection
                    instruments.Add(instrument);
                }

                if (instrument == null)
                {
                    Debug.LogError($"<color=\"aqua\">PyramidInstrumentsParser.ParseInstruments() : Instrument NAME expected on line({i}) : {lines[i]}</color>");
                    return(null);
                }

                ParseLine(lines[i++], out name, out value); //TODO check ParseLine return value

                if (name[0] == 'N')
                {
                    Debug.LogWarning($"<color=\"aqua\">PyramidInstrumentsParser.ParseInstruments() : we got note{int.Parse(name.Substring(1))}</color>");

                    var row = new NoteRowDef();
                    row.SetLabel(value);
                    row.SetNote(new Note(int.Parse(name.Substring(1))));
                    row.SetAlwaysShow(true);

                    instrument.NoteRowDefs.Add(row.Note.Id, row);
                }
                else
                {
                    Debug.LogWarning($"<color=\"aqua\">PyramidInstrumentsParser.ParseInstruments() : we got CC{int.Parse(name)}</color>");

                    var ccNum = int.Parse(name);
                    var ccDef = new CcDef(ccNum);
                    ccDef.SetLabel(value);

                    instrument.CcDefs[ccNum] = ccDef;
                }
            }

            return(instruments);
        }
コード例 #3
0
        public InstrumentDef ParseInstrument(string name, JSONNode json)
        {
            var instrumentDef = new InstrumentDef();

            var defaultPatternString = json[JsonKeys.DEFAULT_PATT];

            Enum.TryParse(defaultPatternString, true, out PatternType defaultPattern);

            // GLOBAL
            instrumentDef.Name        = name;
            instrumentDef.MidiPort    = json[JsonKeys.MIDI_PORT];
            instrumentDef.MidiChannel = json[JsonKeys.MIDI_CHAN];

            if (json[JsonKeys.DEFAULT_NOTE] != "off")
            {
                instrumentDef.DefaultNote = new Note((string)json[JsonKeys.DEFAULT_NOTE]);
            }

            instrumentDef.DefaultPattern = defaultPattern;
            instrumentDef.Multi          = json[JsonKeys.MULTI];
            instrumentDef.PolySpread     = json[JsonKeys.POLY_SPREAD];
            instrumentDef.NoFts          = json[JsonKeys.NO_FTS];
            instrumentDef.NoXpose        = json[JsonKeys.NO_XPOSE];

            Debug.LogWarning($"<color=\"aqua\">InitAppCommand.ParseInstrument() : =================={name}==================</color>");
            Debug.LogWarning($"<color=\"aqua\">InitAppCommand.ParseInstrument() GLOBAL - MidiPort:{instrumentDef.MidiPort}</color>");
            Debug.LogWarning($"<color=\"aqua\">InitAppCommand.ParseInstrument() GLOBAL - MidiChannel:{instrumentDef.MidiChannel}</color>");
            Debug.LogWarning($"<color=\"aqua\">InitAppCommand.ParseInstrument() GLOBAL - DefaultNote:{instrumentDef.DefaultNote}</color>");
            Debug.LogWarning($"<color=\"aqua\">InitAppCommand.ParseInstrument() GLOBAL - DefaultPattern:{instrumentDef.DefaultPattern}</color>");
            Debug.LogWarning($"<color=\"aqua\">InitAppCommand.ParseInstrument() GLOBAL - Multi:{instrumentDef.Multi}</color>");
            Debug.LogWarning($"<color=\"aqua\">InitAppCommand.ParseInstrument() GLOBAL - PolySpread:{instrumentDef.PolySpread}</color>");
            Debug.LogWarning($"<color=\"aqua\">InitAppCommand.ParseInstrument() GLOBAL - NoFts:{instrumentDef.NoFts}</color>");
            Debug.LogWarning($"<color=\"aqua\">InitAppCommand.ParseInstrument() GLOBAL - NoXpose:{instrumentDef.NoXpose}</color>");

            //TRACK VALUES
            var trackValuesJson = json[JsonKeys.TRACK_VALUES];

            foreach (string trackValueKey in trackValuesJson.Keys)
            {
                var slotIndex     = int.Parse(trackValueKey.Substring(TRACK_VALUE_INT_POS));
                var trackValueDef = ParseTrackValueDef(slotIndex, trackValuesJson[trackValueKey]);
                if (trackValueDef != null)
                {
                    instrumentDef.TrackValues[trackValueDef.SlotIndex] = trackValueDef;

                    if (trackValueDef.Type == TrackValueType.MidiCC)
                    {
                        Debug.LogWarning($"<color=\"aqua\">InitAppCommand.ParseInstrument() TRACK VALUE - Label: {trackValueDef.Label}, CC: {trackValueDef.MidiCC}</color>");
                    }
                    else if (trackValueDef.Type == TrackValueType.TrackControl)
                    {
                        Debug.LogWarning($"<color=\"aqua\">InitAppCommand.ParseInstrument() TRACK VALUE - TrackControl: {trackValueDef.TrackControl}</color>");
                    }
                }
            }

            //CC DEFS
            var ccDefsJson = json[JsonKeys.CC_DEFS];

            foreach (string ccDefKey in ccDefsJson.Keys)
            {
                var ccNum     = int.Parse(ccDefKey.Substring(CC_DEF_INT_POS));
                var ccDefJson = ccDefsJson[ccDefKey];
                var ccDef     = new CcDef(ccNum);

                ccDef.SetLabel(ccDefJson[JsonKeys.LABEL]);
                ccDef.SetMinValue(ccDefJson[JsonKeys.MIN_VAL]);

                if (ccDefJson[JsonKeys.MAX_VAL] != null)
                {
                    ccDef.SetMaxValue(ccDefJson[JsonKeys.MAX_VAL]);
                }

                ccDef.SetStartValue(ccDefJson[JsonKeys.START_VAL]);

                instrumentDef.CcDefs[ccNum] = ccDef;

                Debug.LogWarning($"<color=\"aqua\">InitAppCommand.ParseInstrument() CC DEF - Label: {ccDef.Label}, ccNum: {ccDef.CcNum}</color>");
            }

            //NOTE ROWS
            var noteRowsJson = json[JsonKeys.ROW_DEFS];

            foreach (string noteDefKey in noteRowsJson.Keys)
            {
                var noteRowJson = noteRowsJson[noteDefKey];
                var noteRow     = new NoteRowDef();
                noteRow.SetNote(new Note(noteDefKey));
                noteRow.SetLabel(noteRowJson[JsonKeys.LABEL]);
                noteRow.SetAlwaysShow(noteRowJson[JsonKeys.ALWAYS_SHOW]);

                instrumentDef.NoteRowDefs[noteRow.Note.Id] = noteRow;

                Debug.LogWarning($"<color=\"aqua\">InitAppCommand.ParseInstrument() {instrumentDef.Name} - NOTE ROW DEF - Note: {noteRow.Note.Name}, Label: {noteRow.Label}, AlwaysShow: {noteRow.AlwaysShow}, </color>");
            }

            return(instrumentDef);
        }