Example #1
0
        void ExportBars(Track track)
        {
            int lastTempo = -1;
            prevChordId = -1;
            for (int i = 0; i < track.Bars.Count; ++i)
            {
                var bar = track.Bars[i];
                if (gpif.MasterBars.Count <= i)
                {
                    // this only has to be done for the first track, all other tracks
                    // are assumed to have the same bar layout (which makes sense, if
                    // they are supposed to fit together :) ).
                    var masterBar = new MasterBar();
                    masterBar.Time = string.Format("{0}/{1}", bar.TimeNominator, bar.TimeDenominator);
                    gpif.MasterBars.Add(masterBar);
                    if (bar.BeatsPerMinute != lastTempo)
                    {
                        // set tempo for this bar
                        var tempo = new Automation();
                        tempo.Bar = i;
                        tempo.Position = 0;
                        tempo.Linear = false;
                        tempo.Value[0] = bar.BeatsPerMinute;
                        tempo.Value[1] = 2; // no idea what this represents
                        gpif.MasterTrack.Automations.Add(tempo);
                        lastTempo = bar.BeatsPerMinute;
                    }
                }

                // construct a voice for this bar
                var voice = new Voice();
                voice.Id = gpif.Voices.Count;
                foreach (var chord in bar.Chords)
                {
                    int id = ExportOrFindBeat(chord);
                    voice.Beats.Add(id);
                }

                // see if this voice is already available, otherwise add
                var searchVoice = gpif.Voices.Find(x => x.Equals(voice));
                if (searchVoice != null)
                    voice = searchVoice;
                else
                    gpif.Voices.Add(voice);

                // construct the bar
                var gpBar = new Gpif.Bar();
                gpBar.Id = gpif.Bars.Count;
                if (track.Instrument == Track.InstrumentType.Bass)
                    gpBar.Clef = "F4";
                else
                    gpBar.Clef = "G2";
                gpBar.Voices[0] = voice.Id;
                // see if this bar is already available, otherwise add
                var searchBar = gpif.Bars.Find(x => x.Equals(gpBar));
                if (searchBar != null)
                    gpBar = searchBar;
                else
                    gpif.Bars.Add(gpBar);

                // add to master bar
                gpif.MasterBars[i].Bars.Add(gpBar.Id);
            }
        }
Example #2
0
        void ExportBars(Track track)
        {
            int lastTempo = -1;

            prevChordId = -1;
            for (int i = 0; i < track.Bars.Count; ++i)
            {
                var bar = track.Bars[i];
                if (gpif.MasterBars.Count <= i)
                {
                    // this only has to be done for the first track, all other tracks
                    // are assumed to have the same bar layout (which makes sense, if
                    // they are supposed to fit together :) ).
                    var masterBar = new MasterBar();
                    masterBar.Time = string.Format("{0}/{1}", bar.TimeNominator, bar.TimeDenominator);
                    gpif.MasterBars.Add(masterBar);
                    if (bar.BeatsPerMinute != lastTempo)
                    {
                        // set tempo for this bar
                        var tempo = new Automation();
                        tempo.Bar      = i;
                        tempo.Position = 0;
                        tempo.Linear   = false;
                        tempo.Value[0] = bar.BeatsPerMinute;
                        tempo.Value[1] = 2; // no idea what this represents
                        gpif.MasterTrack.Automations.Add(tempo);
                        lastTempo = bar.BeatsPerMinute;
                    }
                }

                // construct a voice for this bar
                var voice = new Voice();
                voice.Id = gpif.Voices.Count;
                foreach (var chord in bar.Chords)
                {
                    int id = ExportOrFindBeat(chord);
                    voice.Beats.Add(id);
                }

                // see if this voice is already available, otherwise add
                var searchVoice = gpif.Voices.Find(x => x.Equals(voice));
                if (searchVoice != null)
                {
                    voice = searchVoice;
                }
                else
                {
                    gpif.Voices.Add(voice);
                }

                // construct the bar
                var gpBar = new Gpif.Bar();
                gpBar.Id = gpif.Bars.Count;
                if (track.Instrument == Track.InstrumentType.Bass)
                {
                    gpBar.Clef = "F4";
                }
                else
                {
                    gpBar.Clef = "G2";
                }
                gpBar.Voices[0] = voice.Id;
                // see if this bar is already available, otherwise add
                var searchBar = gpif.Bars.Find(x => x.Equals(gpBar));
                if (searchBar != null)
                {
                    gpBar = searchBar;
                }
                else
                {
                    gpif.Bars.Add(gpBar);
                }

                // add to master bar
                gpif.MasterBars[i].Bars.Add(gpBar.Id);
            }
        }