public IHttpActionResult Putpitch(int id, pitch pitch) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != pitch.id_pitch) { return(BadRequest()); } db.Entry(pitch).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!pitchExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public static byte ToByte(this pitch p) { byte OCTAVE_SEMITONES = 12; byte C0_VALUE = 12; /* MIDI defines C0 as 12 */ byte octave = p.octave.ToByte(); byte valueForOctave = (byte)(C0_VALUE + octave * OCTAVE_SEMITONES); byte stepSemitone = p.step switch { step.C => 0, step.D => 2, step.E => 4, step.F => 5, step.G => 7, step.A => 9, step.B => 11, _ => throw new InvalidMusicXmlDocumentException(null, $"Received a pitch with a step of {p.step.ToString()}") }; /* alter is a decimal, but microtonal alters aren't supported in a piano */ decimal alterSemitone = (p.alterSpecified || p.alter != 0) ? Math.Floor(p.alter) : 0; return((byte)(valueForOctave + stepSemitone + alterSemitone)); } }
public IHttpActionResult Postpitch(pitch pitch) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.pitch.Add(pitch); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = pitch.id_pitch }, pitch)); }
public IHttpActionResult Deletepitch(int id) { pitch pitch = db.pitch.Find(id); if (pitch == null) { return(NotFound()); } db.pitch.Remove(pitch); db.SaveChanges(); return(Ok(pitch)); }
private void Init(TimesigVector timesig_table, TempoVector tempo_table, int clock_start, int length, int note_number, bool create_rest) { clock_ = clock_start; length_ = length; // 着目している範囲内のテンポのみを取り出す var small_tempo_table = new TempoVector(); small_tempo_table.AddRange( tempo_table .Where((tempo) => clock_start <= tempo.Clock && tempo.Clock < clock_start + length) .Select((tempo) => (TempoTableEntry)tempo.Clone())); // <pitch> エレメントのテンプレートを作成 MusicXML.pitch pitch = null; if (!create_rest) { pitch = new pitch(); int octave = VsqNote.getNoteOctave(note_number) + 1; step step; if (Enum.TryParse <step>(VsqNote.getNoteStringBase(note_number), out step)) { pitch.step = step; } pitch.octave = octave.ToString(); int alter = VsqNote.getNoteAlter(note_number); if (alter != 0) { pitch.alter = alter; pitch.alterSpecified = true; } } int clock_end = clock_start + length; int current_clock = clock_start; while (current_clock < clock_start + length) { int next_bar_clock = timesig_table.getClockFromBarCount(timesig_table.getBarCountFromClock(current_clock) + 1); int next_tempo_change = clock_end; if (small_tempo_table.Count > 0) { try { next_tempo_change = small_tempo_table .First((tempo) => { return(current_clock < tempo.Clock && tempo.Clock < clock_end); }) .Clock; } catch (InvalidOperationException) { } } int next_separation_point = Math.Min(Math.Min(clock_end, next_bar_clock), next_tempo_change); int remain = next_separation_point - current_clock; var template = templates_ .OrderByDescending((note) => note.duration.First) .FirstOrDefault((note) => note.duration.First <= remain); if (template == null) { break; } else { var note = template.Clone(); if (create_rest) { note.rest.Add(new rest()); } else { note.pitch.Add(pitch.Clone()); note.stem = new stem(); note.stem.Value = stemvalue.up; } notes_.Add(note); current_clock += (int)note.duration.First; } } // connect note with tie if (!create_rest && notes_.Count >= 2) { for (int i = 0; i < notes_.Count; ++i) { var note = notes_[i]; var tied_list = new List <tied>(); if (i < notes_.Count - 1) { var start_tie = new tie(); start_tie.type = startstop.start; note.tie.Add(start_tie); var tied = new tied(); tied.type = startstopcontinue.start; tied_list.Add(tied); } if (0 < i) { var stop_tie = new tie(); stop_tie.type = startstop.stop; note.tie.Add(stop_tie); var tied = new tied(); tied.type = startstopcontinue.stop; tied_list.Add(tied); } var notations = new notations(); notations.Items = tied_list.ToArray(); note.notations = new MusicXML.notations[] { notations }; } } }
public void AddPitch(pitch pitch) { this.Items = ArrayExtensions.ArrayAppend(this.Items, pitch); this.ItemsElementName = ArrayExtensions.ArrayAppend(this.ItemsElementName, ItemsChoiceType1.pitch); }