private static async Task <TimeSpan?> GetByContentTypeAsync(Uri url) { if (url == null) { throw new ArgumentNullException(); } // Get content type try { HttpWebRequest req = WebRequest.CreateHttp(url); req.UserAgent = Shared.UserAgent; req.Method = "HEAD"; using (var resp = await req.GetResponseAsync()) { switch (resp.ContentType) { case "application/vnd.apple.mpegurl": return(await HLS.GetPlaylistDurationAsync(url)); case "video/mp4": return(await MP4.GetDurationAsync(url)); default: return(null); } } } catch (WebException ex) when((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound) { throw new VideoNotFoundException(ex); } }
/// <summary> /// Modifies an existing Hue level /// </summary> /// <remarks> /// To reduce Hue use a number smaller than 1. To increase Hue use a number larger tnan 1 /// </remarks> public static Color ModifyHue(Color c, double Hue) { HLS hls = RGB_to_HLS(c); hls.H *= Hue; return(HLS_to_RGB(hls)); }
/// <summary> /// Modifies an existing Saturation level /// </summary> /// <remarks> /// To reduce Saturation use a number smaller than 1. To increase Saturation use a number larger tnan 1 /// </remarks> public static Color ModifySaturation(Color c, double Saturation) { HLS hls = RGB_to_HLS(c); hls.S *= Saturation; return(HLS_to_RGB(hls)); }
/// <summary> /// Modifies an existing brightness level /// </summary> /// <remarks> /// To reduce brightness use a number smaller than 1. To increase brightness use a number larger tnan 1 /// </remarks> public static Color ModifyBrightness(Color c, double brightness) { HLS hls = RGB_to_HLS(c); hls.L *= brightness; return(HLS_to_RGB(hls)); }
/// <summary> /// Sets a track for this Subroutine. /// </summary> /// <param name="Index">The ID of a Hitlist to load.</param> /// <returns>The ID of the track that was set.</returns> private uint SetTrack(uint Index) { m_Hitlist = FileManager.GetHLS(Index); m_Track = FileManager.GetTRK(m_Hitlist.SoundsAndHitlists[(int)Index]); m_SoundID = m_Track.SoundID; return(m_Hitlist.SoundsAndHitlists[(int)Index]); }
/// <summary> /// Converts RGB to HLS /// </summary> public static HLS RGB_to_HLS(Color c) { HLS hls = new HLS(); hls.H = c.GetHue() / 360.0; hls.L = c.GetBrightness(); hls.S = c.GetSaturation(); return(hls); }
public ColorTestCase( byte red, byte green, byte blue, double cyanPercent, double magentaPercent, double yellowPercent, double blackPercent, double hue, double lightnessPercent, double saturationPercent, double brightnessPercent, byte alpha = 255) { Color = new CommonColor(red, green, blue, alpha); CMYK = new CMYK(cyanPercent / 100, magentaPercent / 100, yellowPercent / 100, blackPercent / 100); HLS = new HLS(hue, lightnessPercent / 100, saturationPercent / 100); HSB = new HSB(hue, saturationPercent / 100, brightnessPercent / 100); }
private static async Task <TimeSpan?> GetByNameAsync(Uri url, string youTubeKey = null, ITwitchCredentials twitchCredentials = null) { if (url == null) { throw new ArgumentNullException(); } if (url.AbsolutePath.EndsWith(".mp4", StringComparison.InvariantCultureIgnoreCase)) { // Assume MP4 return(await MP4.GetDurationAsync(url)); } else if (url.AbsolutePath.EndsWith(".m3u8", StringComparison.InvariantCultureIgnoreCase)) { // Assume HLS return(await HLS.GetPlaylistDurationAsync(url)); } else if (url.Authority.EndsWith("vimeo.com")) { return(await Vimeo.GetDurationAsync(url)); } else if (url.Authority.EndsWith("youtube.com") || url.Authority.EndsWith("youtu.be")) { return(youTubeKey == null ? null : await new YouTube(youTubeKey).GetDurationAsync(url)); } else if (url.Authority.EndsWith("dailymotion.com") || url.Authority.EndsWith("dai.ly")) { return(await Dailymotion.GetDurationAsync(url)); } else if (url.Authority.EndsWith("twitch.tv")) { return(await new Twitch(twitchCredentials).GetDurationAsync(url)); } else if (url.Authority.EndsWith("soundcloud.com")) { return(await SoundCloud.GetDurationAsync(url)); } else { return(null); } }
public HLS HLSRoundTripTest(HLS hls) { var color = CommonColor.FromHLS(hls.Hue, hls.Lightness, hls.Saturation); return(new HLS(color.Hue, color.Lightness, color.Saturation)); }
public CommonColor ColorFromHLSTest(HLS hls) => CommonColor.FromHLS(hls.Hue, hls.Lightness, hls.Saturation);
/// <summary> /// Converts a colour from HLS to RGB /// </summary> /// <remarks>Adapted from the algoritm in Foley and Van-Dam</remarks> public static Color HLS_to_RGB(HLS hls) { double r = 0, g = 0, b = 0; double temp1, temp2; if (hls.L == 0) { r = g = b = 0; } else { if (hls.S == 0) { r = g = b = hls.L; } else { temp2 = ((hls.L <= 0.5) ? hls.L * (1.0 + hls.S) : hls.L + hls.S - (hls.L * hls.S)); temp1 = 2.0 * hls.L - temp2; double[] t3 = new double[] { hls.H + 1.0 / 3.0, hls.H, hls.H - 1.0 / 3.0 }; double[] clr = new double[] { 0, 0, 0 }; for (int i = 0; i < 3; i++) { if (t3[i] < 0) { t3[i] += 1.0; } if (t3[i] > 1) { t3[i] -= 1.0; } if (6.0 * t3[i] < 1.0) { clr[i] = temp1 + (temp2 - temp1) * t3[i] * 6.0; } else if (2.0 * t3[i] < 1.0) { clr[i] = temp2; } else if (3.0 * t3[i] < 2.0) { clr[i] = (temp1 + (temp2 - temp1) * ((2.0 / 3.0) - t3[i]) * 6.0); } else { clr[i] = temp1; } } r = clr[0]; g = clr[1]; b = clr[2]; } } return(Color.FromArgb((int)(255 * r), (int)(255 * g), (int)(255 * b))); }
/// <summary> /// This runs one HIT instruction, and should be run once every frame for every subroutine. /// </summary> /// <returns>True if still running, otherwise yields.</returns> public override IEnumerable <object> process() { byte Var1 = 0, Var2 = 0; //Used by waiteq, waitne byte Datafield = 0; //Used by set/getsrcdatafield. byte TrackID = 0, Dest = 0; int Src = 0; if (!SimpleMode) { while (true) { byte Opcode = ReadByte(); switch (Opcode) { case 0x2: //note_on - play a note, whose ID resides in the specified variable. Dest = ReadByte(); if (m_SoundID == 0) { m_SoundID = m_Track.SoundID; } ISoundCodec Snd = FileManager.GetSound(m_SoundID); if (Snd != null) { m_Notes.Add(new HITNoteEntry(m_SoundID, Snd)); SetVariable(Dest, m_Notes.Count - 1); m_Player = new SoundPlayer(Snd.DecompressedWav(), Snd.GetSampleRate()); m_Player.PlaySound(); } else { Debug.WriteLine("SubRoutine.cs: Couldn't find sound " + m_SoundID); } break; case 0x4: //loadb - sign-extend a 1-byte constant to 4 bytes and write to a variable. Dest = ReadByte(); var Constant = (sbyte)ReadByte(); SetVariable(Dest, Constant); m_ZeroFlag = (Dest == 0); m_SignFlag = (Dest < 0); //TODO: When to set this to false again? break; case 0x5: //loadl - write a 4-byte constant to a variable. Dest = ReadByte(); Src = ReadInt32(); SetVariable(Dest, Src); break; case 0x6: //set/settt - copy the contents of one variable into another. Dest = ReadByte(); Src = GetVariable(ReadByte()); SetVariable(Dest, Src); m_ZeroFlag = (Dest == 0); m_SignFlag = (Dest < 0); //TODO: When to set this to false again? break; case 0x7: //call - push the instruction pointer and jump to the given address. m_Stack.Push(m_InstCounter); m_InstCounter = (uint)ReadInt32(); break; case 0x8: //return - kill this thread. m_Player.StopSound(); m_Player.Dispose(); m_Player = null; YieldComplete(); yield return(false); break; case 0x9: //wait - wait for a length of time in milliseconds, specified by a variable. Src = ReadByte(); if (m_WaitRemaining == -1) { m_WaitRemaining = m_Registers[(byte)Src]; } m_WaitRemaining -= 16; //assuming tick rate is 60 times a second if (m_WaitRemaining > 0) { m_InstCounter -= 2; yield return(false); } else { m_WaitRemaining = -1; yield return(false); } break; case 0xb: //wait_samp - wait for the previously selected note to finish playing. break; case 0xc: //end - return from this function; pop the instruction pointer from the stack and jump. YieldComplete(); //Not sure if this is correct? yield return(true); break; case 0xd: //jump - jump to a given address. byte JmpAddress = ReadByte(); if (JmpAddress > 15) { m_InstCounter--; m_InstCounter = ReadUInt32(); } else { m_InstCounter = (uint)GetVariable(JmpAddress); if (ReadByte() == 0) { m_InstCounter += 2; } else { m_InstCounter--; } } break; case 0xe: //test - examine the variable and set the flags. Dest = ReadByte(); m_ZeroFlag = (Dest == 0); m_SignFlag = (Dest < 0); break; case 0xf: //nop - no operation. break; case 0x10: //add - increment a "dest" variable by a "src" variable m_Registers[ReadByte()] += m_Registers[ReadByte()]; m_ZeroFlag = (Dest == 0); m_SignFlag = (Dest < 0); break; case 0x11: //sub - decrement a "dest" variable by a "src" variable. m_Registers[ReadByte()] -= m_Registers[ReadByte()]; m_ZeroFlag = (Dest == 0); m_SignFlag = (Dest < 0); break; case 0x12: //div - divide a "dest" variable by a "src" variable. m_Registers[ReadByte()] /= m_Registers[ReadByte()]; m_ZeroFlag = (Dest == 0); m_SignFlag = (Dest < 0); break; case 0x13: //mul - multiply a "dest" variable by a "src" variable. m_Registers[ReadByte()] *= m_Registers[ReadByte()]; m_ZeroFlag = (Dest == 0); m_SignFlag = (Dest < 0); break; case 0x14: //cmp - compare two variables and set the flags. m_Registers[ReadByte()] -= m_Registers[ReadByte()]; m_ZeroFlag = (Dest == 0); m_SignFlag = (Dest < 0); break; case 0x18: //rand - generate a random number between "low" and "high" variables, inclusive, and store //the result in the "dest" variable. SetVariable(ReadByte(), m_Rand.Next((int)ReadByte(), (int)ReadByte())); break; case 0x20: //loop - jump back to the loop point (start of track subroutine by default). if (m_LoopPoint != 0) { m_InstCounter = m_LoopPoint; } else { m_InstCounter = Address; } break; case 0x021: //set_loop - set the loop point to the current position. m_LoopPoint = m_InstCounter; break; case 0x27: //smart_choose - Set the specified variable to a random entry from the selected hitlist. Dest = ReadByte(); int Max = m_Hitlist.SoundsAndHitlists.Count; SetVariable(Dest, (int)m_Hitlist.SoundsAndHitlists[m_Rand.Next(Max)]); break; case 0x2d: //max - find the higher of a "dest" variable and a "src" constant and store the result //in the variable. Dest = ReadByte(); Src = ReadInt32(); if (Src > Dest) { SetVariable(Dest, Src); } break; case 0x32: //play_trk - play a track (by sending it the kSndobPlay event), whose ID resides in the //specified variable. TrackID = ReadByte(); if (HitVM.IsInitialized) { HitVM.PlayTrack((uint)GetVariable(TrackID)); } break; case 0x33: //kill_trk - kill a track (by sending it the kSndobKill event), whose ID resides in the //specified variable. TrackID = ReadByte(); if (HitVM.IsInitialized) { HitVM.KillTrack((uint)GetVariable(TrackID)); } break; case 0x3a: //test1 - unknown break; case 0x3b: //test2 - unknown break; case 0x3c: //test3 - unknown break; case 0x3d: //test4 - unknown break; case 0x3e: //ifeq - if the zero flag is set, jump to the given address. Src = ReadInt32(); if (m_ZeroFlag) { m_InstCounter = (uint)Src; } break; case 0x3f: //ifne - if the zero flag is not set, jump to the given address. Src = ReadInt32(); if (!m_ZeroFlag) { m_InstCounter = (uint)Src; } break; case 0x40: //ifgt - if the sign flag is not set and the zero flag is not set, jump to the given address. Src = ReadInt32(); if (!m_ZeroFlag && !m_SignFlag) { m_InstCounter = (uint)Src; } break; case 0x41: //iflt - if the sign flag is set, jump to the given address. Src = ReadInt32(); if (m_SignFlag) { m_InstCounter = (uint)Src; } break; case 0x42: //ifge - if the sign flag is not set, jump to the given address. Src = ReadInt32(); if (!m_SignFlag) { m_InstCounter = (uint)Src; } break; case 0x43: //ifle - if the sign flag is set or the zero flag is set, jump to the given address. Src = ReadInt32(); if (m_ZeroFlag || m_SignFlag) { m_InstCounter = (uint)Src; } break; case 0x44: //smart_setlist - choose a global hitlist, or 0 for the one local to the track. Src = ReadByte(); if (Src != 0) { m_Hitlist = FileManager.GetHLS((uint)GetVariable(Src)); } else { uint SoundID = FileManager.GetTRK(TrackID).SoundID; try { FileManager.GetSound(SoundID); } catch { m_Hitlist = FileManager.GetHLS(SoundID); } } break; case 0x45: //seqgroup_kill - kill all sounds belonging to the sequence group specified by the "group" //variable. Src = ReadByte(); break; case 0x47: //seqgroup_return - unknown. byte Group = ReadByte(); break; case 0x48: //getsrcdatafield - Read an object variable (whose ID is specified by the "field" //variable) of a source object (whose object ID is specified by the "source" variable), //store it in the "dest" variable, and update the flags. Dest = ReadByte(); Src = ReadByte(); Datafield = ReadByte(); int ObjectVar = GetVariable(Src); SetVariable(Dest, ObjectVar); m_ZeroFlag = (ObjectVar == 0); m_SignFlag = (ObjectVar < 0); break; case 0x49: //seqgroup_trkid - unknown. Dest = ReadByte(); Src = ReadByte(); break; case 0x4a: //setll - Copy the contents of one variable into another (equivalent to set and settt; //defaultsyms.txt says "ISN'T THIS THE SAME AS SET TOO?") Dest = ReadByte(); Src = ReadByte(); SetVariable(Dest, Src); break; case 0x4b: //setlt - unknown. Dest = ReadByte(); Src = ReadByte(); break; case 0x4d: //waiteq - wait until two variables are equal. Var1 = ReadByte(); Var2 = ReadByte(); if (GetVariable(Var1) != GetVariable(Var2)) { m_InstCounter -= 3; yield return(false); } break; case 0x53: //duck - unknown. break; case 0x54: //unduck - unknown. break; case 0x56: //setlg - set global = local (source: defaultsyms.txt). Dest = ReadByte(); Src = ReadInt32(); HitVM.SetGlobalVar(Src, GetVariable(Dest)); break; case 0x57: //setgl - read globally, set locally (source: defaultsyms.txt). Dest = ReadByte(); Src = ReadInt32(); SetVariable(Dest, HitVM.GetGlobalVar(Src)); break; case 0x59: //setsrcdatafield - set an object variable (whose ID is specified by the "field" variable) of //a source object (whose object ID is specified by the "source" variable) to the value //specified by the "value" variable. Dest = ReadByte(); Src = ReadByte(); Datafield = ReadByte(); break; case 0x5f: //smart_index - find the entry at the index specified by the "index" variable in the hitlist //specified by the "dest" variable and store that entry in the "dest" variable. Dest = ReadByte(); byte Index = ReadByte(); uint HitlistID = (uint)GetVariable(Index); uint TRKID = SetTrack(HitlistID); SetVariable(Dest, (int)TRKID); break; case 0x60: //note_on_loop - play a note, whose ID resides in the specified variable, and immediately loop //it indefinitely. Dest = ReadByte(); HITNoteEntry Note = new HITNoteEntry(m_SoundID, FileManager.GetSound(m_SoundID)); m_Notes.Add(Note); SetVariable(Dest, m_Notes.Count - 1); m_Player = new SoundPlayer(Note.Sound.DecompressedWav(), Note.Sound.GetSampleRate()); m_Player.PlaySound(); break; } } } else { ISoundCodec Snd = FileManager.GetSound(m_SoundID); m_Player = new SoundPlayer(Snd.DecompressedWav(), Snd.GetSampleRate()); m_Player.PlaySound(); yield return(true); } }