private static void ListInstrumentsJSON(WebContext context, Song s) { JSONWriter jw = new JSONWriter(); jw.Array(); for (int k = 0; k < s.Instruments.Count; k++) { Instrument ins = s.Instruments[k]; jw.Class(); jw.Field("id", ins.ID); jw.Field("name", ins.Name); jw.Field("device", ins.MidiDevice); jw.Field("channel", ins.MidiChannel); jw.Field("patch", ins.MidiPatch); jw.Field("type", ins.Type); jw.End(); } jw.End(); context.Response.Write("g_Instruments = "); context.Response.Write(jw.ToString(JSONFormatting.Pretty)); context.Response.Write(";\n"); }
private static void ListAutomationChannelsJSON(WebContext context, Song s) { JSONWriter jw = new JSONWriter(); jw.Array(); for (int j = 0; j < s.Tracks.Count; j++) { // SongTrack st = s.Tracks[j]; jw.Class(); jw.Field("id", j); jw.Field("name", "Automation #" + j); jw.End(); } jw.End(); context.Response.Write("g_AutomationTracks = "); context.Response.Write(jw.ToString(JSONFormatting.Pretty)); context.Response.Write(";\n"); }
private void GetPatternList(WebContext context) { // string ins = context.Request.GetParameter("getpatternlist"); Song s = State.CurrentSong; JSONWriter jw = new JSONWriter(); jw.Class(); jw.Array("patterns"); for (int k = 0; k < s.Patterns.Count; k++) { Pattern p = s.Patterns[k]; // if (p.InstrumentID == ins) { jw.Class(); jw.Field("id", p.ID); jw.Field("name", p.Name); jw.End(); } } jw.End(); jw.End(); context.Response.ContentType = "text/javascript"; context.Response.Write(jw.ToString()); }
private void GetPattern(WebContext context) { string pat = context.Request.GetParameter("getpattern"); Song s = State.CurrentSong; Pattern p = s.GetPatternByID(pat); JSONWriter jw = new JSONWriter(); jw.Class(); jw.Field("id", p.ID); jw.Field("duration", p.Duration); jw.Field("name", p.Name); jw.Array("notes"); for (int k = 0; k < p.Notes.Count; k++) { PatternNote n = p.Notes[k]; jw.Class(); jw.Field("id", n.ID); jw.Field("from", n.From); jw.Field("to", n.To); jw.Field("note", n.Note); jw.Field("velocity", n.Velocity); jw.End(); } jw.End(); jw.Array("automations"); for (int k = 0; k < p.Automations.Count; k++) { PatternAutomation am = p.Automations[k]; jw.Class(); jw.Field("id", am.ID); jw.Field("channel", am.Channel); jw.Field("macro", am.Macro); jw.Array("points"); for (int j = 0; j < am.Keys.Count; j++) { PatternAutomationKey amk = am.Keys[j]; jw.Class(); jw.Field("id", amk.ID); jw.Field("time", amk.Time); jw.Field("value", amk.Value); jw.End(); } jw.End(); jw.End(); } jw.End(); jw.End(); context.Response.ContentType = "text/javascript"; context.Response.Write(jw.ToString()); }
private void GetMidiDeviceList(WebContext context) { string sid = context.Request.GetParameter("getmididevicelist"); JSONWriter jw = new JSONWriter(); jw.Class(); jw.Array("devices"); List<int> ids = MidiWrapper.GetDeviceIDs(); for (int k = 0; k < ids.Count; k++) { string nam = MidiWrapper.GetDeviceName(ids[k]); jw.Class(); jw.Field("id", ids[k]); jw.Field("name", nam); jw.End(); } jw.End(); jw.End(); context.Response.ContentType = "text/javascript"; context.Response.Write(jw.ToString()); }
private void GetInstrumentList(WebContext context) { Song s = State.CurrentSong; JSONWriter jw = new JSONWriter(); jw.Class(); jw.Array("instruments"); for (int k = 0; k < s.Instruments.Count; k++) { Instrument ins = s.Instruments[k]; jw.Class(); jw.Field("id", ins.ID); jw.Field("name", ins.Name); jw.Field("type", ins.Type); jw.End(); } jw.End(); jw.End(); context.Response.ContentType = "text/javascript"; context.Response.Write(jw.ToString()); }
public ActionResult Users(string method, string id) { string token = Request["token"]; string userid = APITokens.GetUserID(token); if (method == "get") { } else if (method == "list") { JSONWriter jw = new JSONWriter(); jw.Class(); jw.Array("users"); DBDataContext db = new DBDataContext(); var users = from u in db.Users orderby u.UserName ascending select u; // if (computerid != 0) // vols = from v in vols where v.ComputerID.Equals(computerid) select v; foreach (Users u in users) { jw.Class(); jw.Field("id", u.UserID.ToString()); jw.Field("name", u.UserName); jw.End(); } jw.End(); jw.End(); return new JSONResponseResult(jw.ToString(JSONFormatting.Pretty)); } else if (method == "add") { if (string.IsNullOrEmpty(userid)) return new JSONResponseResult("not authenticated"); } else if (method == "remove") { if (string.IsNullOrEmpty(userid)) return new JSONResponseResult("not authenticated"); } return new JSONResponseResult("unknown users-command; method=" + method + ", id=" + id); }
public static void ReturnJSON(JSONWriter jw) { ReturnJavascript(jw.ToString(JSONFormatting.Pretty)); }
private void GetTrackList(WebContext context) { string sid = context.Request.GetParameter("gettracklist"); Song s = State.CurrentSong; JSONWriter jw = new JSONWriter(); jw.Class(); jw.Array("tracks"); for (int k = 0; k < s.Tracks.Count; k++) { SongTrack tr = s.Tracks[k]; // if (tr.ID == insid) { jw.Class(); jw.Field("id", tr.ID); jw.Field("name", tr.Name); if (tr.CurrentPatternID != null) jw.Field("pattern", tr.CurrentPatternID); else jw.Field("pattern", ""); if (tr.CuedPatternID != null) jw.Field("cued", tr.CuedPatternID); else jw.Field("cued", ""); jw.Field("volume", tr.Volume); jw.Field("transpose", tr.Transpose); jw.Field("mute", tr.Muted ? 1 : 0); jw.Field("solo", tr.Solo ? 1 : 0); jw.End(); // jw.Field("type", ins.Type); // jw.Field("mididevice", ins.MidiDevice); // jw.Field("midichannel", ins.MidiChannel); // jw.Field("midipatch", ins.MidiPatch); } } jw.End(); jw.End(); context.Response.ContentType = "text/javascript"; context.Response.Write(jw.ToString()); }
private static void ListTracksJSON(WebContext context, Song s) { JSONWriter jw = new JSONWriter(); jw.Array(); for (int j = 0; j < s.Tracks.Count; j++) { SongTrack st = s.Tracks[j]; jw.Class(); jw.Field("id", st.ID); jw.Field("name", st.Name); if (st.CurrentPatternID != null) jw.Field("pattern", st.CurrentPatternID); else jw.Field("pattern", ""); if (st.CuedPatternID != null) jw.Field("cued", st.CuedPatternID); else jw.Field("cued", ""); jw.Field("volume", st.Volume); jw.Field("transpose", st.Transpose); jw.Field("mute", st.Muted ? 1 : 0); jw.Field("solo", st.Solo ? 1 : 0); jw.End(); } jw.End(); context.Response.Write("g_Tracks = "); context.Response.Write(jw.ToString(JSONFormatting.Pretty)); context.Response.Write(";\n"); }
private static void ListSongJSON(WebContext context, Song s) { JSONWriter jw = new JSONWriter(); jw.Class(); jw.Field("bpm", s.BPM); jw.Field("beats1", s.Beats1); jw.Field("beats2", s.Beats2); jw.End(); context.Response.Write("g_Song = "); context.Response.Write(jw.ToString(JSONFormatting.Pretty)); context.Response.Write(";\n"); }
private static void ListPatternsJSON(WebContext context, Song s) { JSONWriter jw = new JSONWriter(); jw.Array(); for (int j = 0; j < s.Patterns.Count; j++) { Pattern p = s.Patterns[j]; jw.Class(); jw.Field("id", p.ID); jw.Field("instrument", p.InstrumentID); jw.Field("name", p.Name); jw.Field("duration", p.Duration); jw.Array("notes"); for (int k = 0; k < p.Notes.Count; k++) { PatternNote pn = p.Notes[k]; jw.Class(); jw.Field("id", pn.ID); jw.Field("from", pn.From); jw.Field("to", pn.To); jw.Field("note", pn.Note); jw.Field("velocity", pn.Velocity); jw.End(); } jw.End(); jw.Array("automations"); for (int k = 0; k < p.Automations.Count; k++) { PatternAutomation pa = p.Automations[k]; jw.Class(); jw.Field("id", pa.ID); jw.Field("macro", pa.Macro); jw.Field("channel", pa.Channel); jw.Array("keys"); for (int u = 0; u < pa.Keys.Count; u++) { jw.Class(); jw.Field("id", pa.Keys[u].ID); jw.Field("time", pa.Keys[u].Time); jw.Field("value", pa.Keys[u].Value); jw.End(); } jw.End(); jw.End(); } jw.End(); jw.End(); } jw.End(); context.Response.Write("g_Patterns = "); context.Response.Write(jw.ToString(JSONFormatting.Pretty)); context.Response.Write(";\n"); }
public static string ToJSONString <T>(T obj) { JSONElement jsonElement = ToJSONElement(obj); return(JSONWriter.ToString(jsonElement)); }
public ActionResult Computers(string method, string id) { string token = Request["token"]; string userid = APITokens.GetUserID(token); if (method == "get") { } else if (method == "list") { string username = Request["user"]; JSONWriter jw = new JSONWriter(); jw.Class(); jw.Array("computers"); DBDataContext db = new DBDataContext(); IEnumerable<Computers> comps = from c in db.Computers orderby c.ComputerName ascending select c; if (!string.IsNullOrEmpty(username)) comps = from c in comps where c.UserID.ToString().Equals(username) select c; foreach (Computers c in comps) { jw.Class(); jw.Field("id", c.ID); jw.Field("name", c.ComputerName); if (c.CreatedDate.HasValue) jw.Field("date", c.CreatedDate.Value.ToString("R")); if (c.Users != null) { jw.Field("userid", c.Users.UserID.ToString()); jw.Field("username", c.Users.UserName); } // int totalused = (from v in db.Volumes, m in v.Measures select v.MeasureUsed select ).Sum(); int? totalused2 = 0; try { totalused2 = ( from v2 in db.Volumes where v2.ComputerID.Equals(c.ID) select ( from m in v2.Measures where m.VolumeID.Equals(v2.ID) orderby m.MeasureDate descending select m.MeasureUsed ).First() ).Sum(); } catch (Exception) { } int? totalsize2 = 0; try { totalsize2 = ( from v2 in db.Volumes where v2.ComputerID.Equals(c.ID) select ( from m in v2.Measures where m.VolumeID.Equals(v2.ID) orderby m.MeasureDate descending select m.MeasureSize ).First() ).Sum(); } catch (Exception) { } if (totalsize2.HasValue) jw.Field("totalsize", totalsize2.Value); else jw.Field("totalsize", 0); if (totalused2.HasValue) jw.Field("totalused", totalused2.Value); else jw.Field("totalused", 0); jw.Array("volumes"); IEnumerable<Volume> vols = from v in c.Volumes orderby v.VolumeName select v; foreach (Volume v in vols) { jw.Class(); jw.Field("id", v.ID); if (v.VolumeName != null) jw.Field("name", v.VolumeName); else jw.Field("name", ""); int? numsamples = null; try { numsamples = (from m in v.Measures where m.VolumeID.Equals(v.ID) select m).Count(); } catch (Exception) { } DateTime? lastsample = null; try { lastsample = (from m in v.Measures where m.VolumeID.Equals(v.ID) orderby m.MeasureDate descending select m.MeasureDate).First(); } catch (Exception) { } int? totalused = 0; try { totalused = (from m in v.Measures where m.VolumeID.Equals(v.ID) orderby m.MeasureDate descending select m.MeasureUsed).First(); } catch (Exception) { } int? totalsize = 0; try { totalsize = (from m in v.Measures where m.VolumeID.Equals(v.ID) orderby m.MeasureDate descending select m.MeasureSize).First(); } catch (Exception) { } jw.Field("samples", numsamples.Value); if (lastsample.HasValue) jw.Field("last", lastsample.Value.ToString("R")); jw.Field("used", totalused.Value); jw.Field("size", totalsize.Value); jw.End(); } jw.End(); jw.End(); } jw.End(); jw.End(); return new JSONResponseResult(jw.ToString(JSONFormatting.Pretty)); } else if (method == "add") { if (string.IsNullOrEmpty(userid)) return new JSONResponseResult("not authenticated"); string un = Request["username"]; // int compid = 0; // int.TryParse(Request["computer"], out compid); int volid = 0; int.TryParse(Request["volume"], out volid); int ds = 0; int.TryParse(Request["disksize"], out ds); int du = 0; int.TryParse(Request["diskused"], out du); DBDataContext db = new DBDataContext(); var user = from u in db.Users where u.UserName.Equals(un) select u; if (user != null) { Measure m = new Measure(); m.MeasureSize = ds; m.MeasureUsed = du; m.VolumeID = volid; m.MeasureDate = DateTime.Now; db.Measures.InsertOnSubmit(m); db.SubmitChanges(); return new JSONResponseResult("ok"); } } else if (method == "remove") { if (string.IsNullOrEmpty(userid)) return new JSONResponseResult("not authenticated"); } return new JSONResponseResult("unknown computers-command; method=" + method + ", id=" + id); }
public ActionResult Volumes(string method, string id) { string token = Request["token"]; string userid = APITokens.GetUserID(token); if (method == "get") { return new JSONResponseResult("ok"); } else if (method == "list") { int computerid = 0; if (!string.IsNullOrEmpty(Request["token"])) int.TryParse(Request["token"], out computerid); JSONWriter jw = new JSONWriter(); jw.Class(); jw.Array("volumes"); DBDataContext db = new DBDataContext(); var vols = from v in db.Volumes select v; if (computerid != 0) vols = from v in vols where v.ComputerID.Equals(computerid) select v; foreach (Volume v in vols) { jw.Class(); jw.Field("id", v.ID); jw.Field("name", v.VolumeName); if (v.Computers != null) { jw.Field("computerid", v.Computers.ID); jw.Field("computername", v.Computers.ComputerName); } jw.End(); } jw.End(); jw.End(); return new JSONResponseResult(jw.ToString(JSONFormatting.Pretty)); } else if (method == "add") { if (string.IsNullOrEmpty(userid)) return new JSONResponseResult("not authenticated"); int compid = 0; int.TryParse(Request["computer"], out compid); int ds = 0; int.TryParse(Request["disksize"], out ds); int du = 0; int.TryParse(Request["diskused"], out du); DBDataContext db = new DBDataContext(); Volume v = new Volume(); v.ComputerID = compid; v.CreatedDate = DateTime.Now; db.Volumes.InsertOnSubmit(v); db.SubmitChanges(); return new JSONResponseResult("{ status:'ok', id:'" + v.ID + "' }"); } else if (method == "remove") { if (string.IsNullOrEmpty(userid)) return new JSONResponseResult("not authenticated"); } return new JSONResponseResult("unknown volumes-command; method=" + method + ", id=" + id); }
private void GetTiming(WebContext context) { // throw new NotImplementedException(); string sid = context.Request.GetParameter("gettiming"); Song s = State.CurrentSong; JSONWriter jw = new JSONWriter(); jw.Class(); jw.Field("bpm", s.BPM); jw.Field("measure1", s.Beats1); jw.Field("measure2", s.Beats2); jw.End(); context.Response.ContentType = "text/javascript"; context.Response.Write(jw.ToString()); }
private void GetAutomationChannels(WebContext context) { JSONWriter jw = new JSONWriter(); jw.Class(); jw.Array("channels"); for (int k = 0; k < 127; k++) { jw.Class(); jw.Field("id", k); jw.Field("name", "Automation channel " + k); jw.End(); } jw.End(); jw.End(); context.Response.ContentType = "text/javascript"; context.Response.Write(jw.ToString()); }
private static void ListMidiDevicesJSON(WebContext context, Song s) { JSONWriter jw = new JSONWriter(); jw.Array(); List<int> ids = MidiWrapper.GetDeviceIDs(); for (int k = 0; k < ids.Count; k++) { string nam = MidiWrapper.GetDeviceName(ids[k]); jw.Class(); jw.Field("id", ids[k]); jw.Field("name", nam); jw.End(); } jw.End(); context.Response.Write("g_MidiDevices = "); context.Response.Write(jw.ToString(JSONFormatting.Pretty)); context.Response.Write(";\n"); }
private void GetInstrument(WebContext context) { string insid = context.Request.GetParameter("getinstrument"); Song s = State.CurrentSong; JSONWriter jw = new JSONWriter(); jw.Class(); for (int k = 0; k < s.Instruments.Count; k++) { Instrument ins = s.Instruments[k]; if (ins.ID == insid) { jw.Field("id", ins.ID); jw.Field("name", ins.Name); jw.Field("type", ins.Type); jw.Field("mididevice", ins.MidiDevice); jw.Field("midichannel", ins.MidiChannel); jw.Field("midipatch", ins.MidiPatch); } } jw.End(); context.Response.ContentType = "text/javascript"; context.Response.Write(jw.ToString()); }
public override string ToString() { SerialiseData(); return(data.ToString()); }
public ActionResult Measures(string method, string id) { string token = Request["token"]; string userid = APITokens.GetUserID(token); if (method == "get") { } else if (method == "list") { int volumeid = 0; if (!string.IsNullOrEmpty(Request["volume"])) int.TryParse(Request["volume"], out volumeid); JSONWriter jw = new JSONWriter(); jw.Class(); jw.Array("measurements"); DBDataContext db = new DBDataContext(); var measurements = from m in db.Measures select m; if (volumeid != 0) measurements = from m in measurements where m.VolumeID.Equals(volumeid) select m; measurements = from m in measurements orderby m.MeasureDate descending select m; foreach (Measure m in measurements) { jw.Class(); jw.Field("id", m.ID); if (m.MeasureDate.HasValue) jw.Field("date", m.MeasureDate.Value.ToString("R")); jw.Field("size", m.MeasureSize.ToString()); jw.Field("used", m.MeasureUsed.ToString()); jw.End(); } jw.End(); jw.End(); return new JSONResponseResult(jw.ToString(JSONFormatting.Pretty)); } else if (method == "add") { if (string.IsNullOrEmpty(userid)) return new JSONResponseResult("not authenticated"); string un = Request["username"]; // int compid = 0; // int.TryParse(Request["computer"], out compid); int volid = 0; int.TryParse(Request["volume"], out volid); int ds = 0; int.TryParse(Request["disksize"], out ds); int du = 0; int.TryParse(Request["diskused"], out du); DBDataContext db = new DBDataContext(); var user = from u in db.Users where u.UserName.Equals(un) select u; if (user != null) { Measure m = new Measure(); m.MeasureSize = ds; m.MeasureUsed = du; m.VolumeID = volid; m.MeasureDate = DateTime.Now; db.Measures.InsertOnSubmit(m); db.SubmitChanges(); return new JSONResponseResult("ok"); } } else if (method == "remove") { if (string.IsNullOrEmpty(userid)) return new JSONResponseResult("not authenticated"); } return new JSONResponseResult("unknown measures-command; method=" + method + ", id=" + id); }