Skip to content

Instantly share code, notes, and snippets.

import Data.Maybe (fromJust, catMaybes)
import Data.List (subsequences, findIndex, findIndices)
import Data.Word(Word8)
import qualified Data.ByteString.Lazy as BL
import Data.Binary.Put
data Op = UP | DN deriving (Show, Eq)
-- Generalizaciones (limpiar; mala estructura, usar folds)
import Haskore.Interface.MIDI.Render
import Haskore.Melody
import Haskore.Music.GeneralMIDI as GM
import qualified Haskore.Music as Music
test m = fileFromGeneralMIDIMusic "test.mid" $ GM.fromMelodyNullAttr AcousticGrandPiano m
riff = line [utp, mi, sol, ti] where
utp = chord [ut, mi, sol]
ut = c 2 en ()
-- para construir: "ghci yidl.hs" seguido de "render todo" crea "yidl.mid"
import Haskore.Basic.Duration
import Haskore.Interface.MIDI.Render
import Haskore.Melody
import Haskore.Basic.Interval
import Haskore.Music.GeneralMIDI as GM
import Haskore.Basic.Scale
import Haskore.Basic.Tempo
import Haskore.Basic.Pitch as BP
import Haskore.Basic.Duration
import Haskore.Interface.MIDI.Render
import Haskore.Melody
import Haskore.Basic.Interval
import Haskore.Music.GeneralMIDI as GM
import Haskore.Basic.Scale
import Haskore.Basic.Tempo
import Haskore.Basic.Pitch as BP
import qualified Haskore.Music as Music
import Haskore.Basic.Duration
import Haskore.Interface.MIDI.Render
import Haskore.Melody
import Haskore.Basic.Interval
import Haskore.Music.GeneralMIDI as GM
import Haskore.Basic.Scale
import Haskore.Basic.Tempo
import Haskore.Basic.Pitch as BP
import qualified Haskore.Music as Music
import Data.Numbers.Primes(primes)
import Data.List(sort, sortBy)
rad :: Integer -> Integer
rad n = product $ f n primes where
f :: Integer -> [Integer] -> [Integer]
f 1 _ = []
f x (y:ys) = if mod x y == 0
then y : f (remove y x) ys
else f x ys
import Data.List(sort)
import Math.Algebra.Group.PermutationGroup(fromPairs)
data Op = DN | UP deriving (Show, Eq, Ord)
paso :: (Integral a) => (a -> a) -> a -> a
paso hazpar x = if odd x then div (hazpar x) 2 else div x 2
-- 'take n $ serieInfinita binarios x' da una representación binaria de
-- x truncada a n bits, 'DN' es 0, 'UP' es 1, el primer bit en la cadena
-- medidor de beat
-- compilar: 'ghc --make beat.hs'
-- cuenta distancias en milisegundos entre clicks de teclado
-- salir con 'q'
import qualified Graphics.UI.SDL as SDL
import Graphics.UI.SDL.Keysym as K
import Graphics.UI.SDL.Time as T
import Data.Word(Word32)
import Data.Array
data Op = DN | UP deriving (Show, Eq, Ord)
paso :: (Integral a) => (a -> a) -> a -> a
paso hazpar x = if odd x then div (hazpar x) 2 else div x 2
serieInfinita :: (Integral a) => (a -> a) -> a -> [Op]
serieInfinita f x = (if odd x then UP else DN) : serieInfinita f siguiente where
siguiente = paso f x
import Data.List(findIndex,findIndices)
import Maybe(fromJust)
paso :: (Integral a) => (a -> a) -> a -> a
paso hazpar x = if odd x then div (hazpar x) 2 else div x 2
serieInfinita :: (Integral a) => (a -> a) -> a -> [Bool]
serieInfinita f x = odd x : serieInfinita f siguiente where
siguiente = paso f x