protected override void ShowInstrumentData(InstrumentDef instrumentDef)
        {
            var inst = InstrumentsModel.GetEditedInstrument();

            if (inst == null)
            {
                return;
            }

            View.InstrumentNameInput.text        = inst.Name;
            View.MidiPortDropdown.value          = inst.MidiPort - 1;
            View.MidiChannelDropdown.value       = inst.MidiChannel - 1;
            View.DefaultNoteDropdown.value       = inst.DefaultNote.NoteIndex;
            View.DefaultNoteOctaveDropdown.value = inst.DefaultNote.OctaveIndex;
            View.DefaultPatternDropdown.value    = (int)inst.DefaultPattern;

            View.DefaultPatternDropdown.value = (int)inst.DefaultPattern;
            View.MultiToggle.isOn             = inst.Multi;
            View.PolySpreadToggle.isOn        = inst.PolySpread;
            View.NoTransposeToggle.isOn       = inst.NoXpose;
            View.NoFtsToggle.isOn             = inst.NoFts;

            if (inst.Name == InstrumentDef.DEFAULT_NAME)
            {
                View.InstrumentNameInput.Select();
            }
        }
 private void EditedInstrumentChangedHandler(InstrumentDef instrumentDef)
 {
     if (instrumentDef != null)
     {
         ShowInstrumentData(instrumentDef);
     }
 }
        public override void Execute()
        {
            var newInstrument   = new InstrumentDef();
            var newInstrumentId = InstrumentsModel.AddInstrument(newInstrument);

            InstrumentsModel.SelectEditedInstrument(newInstrumentId);
            EditedInstrumentChangedSignal.Dispatch(newInstrument);
        }
Beispiel #4
0
        public int AddInstrument(InstrumentDef instrument)
        {
            var id = _instrumentById.Count;

            _instruments.Add(instrument);
            _instrumentById[id] = instrument;

            return(id);
        }
Beispiel #5
0
        /// <summary>Send a midi patch immediately.</summary>
        /// <param name="chanName"></param>
        /// <param name="patch"></param>
        protected void SendPatch(string chanName, InstrumentDef patch)
        {
            var channel = GetChannel(chanName);

            if (channel is not null)
            {
                StepPatch step = new()
                {
                    Device        = channel.Device,
                    ChannelNumber = channel.ChannelNumber,
                    Patch         = patch
                };

                channel.Device?.Send(step);
            }
        }
Beispiel #6
0
        static InstrumentDef extract_instrument_def(byte[] file_contents, int instrument_def_address)
        {
            InstrumentDef instrument_def = new InstrumentDef();

            instrument_def.instrument_type = read_8_bit_from_file_at_offset(file_contents, instrument_def_address);

            instrument_def.data_1   = read_32_bit_from_file_at_offset(file_contents, instrument_def_address);
            instrument_def_address += 4;

            instrument_def.ptr_1    = read_32_bit_from_file_at_offset(file_contents, instrument_def_address);
            instrument_def_address += 4;

            instrument_def.ptr_2    = read_32_bit_from_file_at_offset(file_contents, instrument_def_address);
            instrument_def_address += 4;

            return(instrument_def);
        }
Beispiel #7
0
 private void EditedInstrumentChangedHandler(InstrumentDef instrumentDef)
 {
     ShowEditedInstrument();
 }
        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);
        }
Beispiel #9
0
 static void write_instrument_def_to_bytearray(InstrumentDef instrument_def, List <byte> arr)
 {
     arr.AddRange(BitConverter.GetBytes(instrument_def.data_1));
     arr.AddRange(BitConverter.GetBytes(instrument_def.ptr_1));
     arr.AddRange(BitConverter.GetBytes(instrument_def.ptr_2));
 }
        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);
        }
Beispiel #11
0
        private void UpdateInstrument(InstrumentDef instrument)
        {
            var listData = instrument.TrackValues.Values.Select(tv => new TrackValueDataProvider(tv)).ToList();

            SetData(listData);
        }
 protected abstract void ShowInstrumentData(InstrumentDef instrumentDef);