Skip to content

Commit

Permalink
Configuration Karma
Browse files Browse the repository at this point in the history
  • Loading branch information
Bludwarf committed Mar 17, 2024
1 parent 895376c commit 1449fb3
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 88 deletions.
21 changes: 21 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage'),
require('@angular-devkit/build-angular/plugins/karma'),
],
browsers: ['Chrome'],
files: [
{pattern: 'src/assets/als/*.als', included: false, watched: false, served: true},
{pattern: 'src/assets/als/*.als.xml', included: false, watched: false, served: true},
],
});
};
108 changes: 55 additions & 53 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,55 @@
{
"name": "angular.io-example",
"version": "0.0.0",
"description": "Example project from an angular.io guide.",
"license": "MIT",
"engines": {
"node": "18",
"npm": "10"
},
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "17",
"@angular/common": "17",
"@angular/compiler": "17",
"@angular/core": "17",
"@angular/forms": "17",
"@angular/platform-browser": "17",
"@angular/platform-browser-dynamic": "17",
"@angular/router": "17",
"angular-in-memory-web-api": "0.17",
"rxjs": "7.8",
"tone": "14",
"tslib": "2.3",
"zone.js": "0.14"
},
"devDependencies": {
"@angular-devkit/build-angular": "17",
"@angular/cli": "17",
"@angular/compiler-cli": "17",
"@types/jasmine": "5",
"@types/node": "16",
"copyfiles": "2",
"jasmine-core": "5",
"jasmine-marbles": "0.9",
"jasmine-spec-reporter": "7",
"karma": "6",
"karma-chrome-launcher": "3",
"karma-coverage": "2",
"karma-jasmine": "5",
"karma-jasmine-html-reporter": "2",
"protractor": "7",
"ts-node": "10",
"typescript": "5.2"
}
}
{
"name": "angular.io-example",
"version": "0.0.0",
"description": "Example project from an angular.io guide.",
"license": "MIT",
"engines": {
"node": "18",
"npm": "10"
},
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "17",
"@angular/common": "17",
"@angular/compiler": "17",
"@angular/core": "17",
"@angular/forms": "17",
"@angular/platform-browser": "17",
"@angular/platform-browser-dynamic": "17",
"@angular/router": "17",
"angular-in-memory-web-api": "0.17",
"rxjs": "7.8",
"tone": "14",
"tslib": "2.3",
"zone.js": "0.14"
},
"devDependencies": {
"@angular-devkit/build-angular": "17",
"@angular/cli": "17",
"@angular/compiler-cli": "17",
"@types/jasmine": "5",
"@types/node": "16",
"copyfiles": "2",
"jasmine-core": "5",
"jasmine-marbles": "0.9",
"jasmine-spec-reporter": "7",
"karma": "6",
"karma-chrome-launcher": "3",
"karma-coverage": "2",
"karma-coverage-istanbul-reporter": "3",
"karma-jasmine": "5",
"karma-jasmine-html-reporter": "2",
"karma-junit-reporter": "2",
"protractor": "7",
"ts-node": "10",
"typescript": "5.2"
}
}
122 changes: 87 additions & 35 deletions src/app/structure/structure.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,99 @@
import { Time } from "../time";
import { Pattern } from "./pattern/pattern";
import * as Tone from 'tone'
import { PatternInStructure } from "./pattern/pattern-in-structure";
import {Time} from "../time";
import {Pattern} from "./pattern/pattern";
import {PatternInStructure} from "./pattern/pattern-in-structure";
import * as Tone from "tone";
import {StructureObject} from "../als/structure-extractor-from-als";

class StructureBuilder {
private _stuctureObject?: StructureObject;
private _patterns?: Pattern[];
private _getEventsStartTime?: (pattern: Pattern) => (Time) | undefined;
private _getEventsDurationInBars?: (pattern: Pattern) => number | undefined

stuctureObject(stuctureObject: typeof this._stuctureObject) {
this._stuctureObject = stuctureObject;
return this
}

patterns(patterns: typeof this._patterns) {
this._patterns = patterns
return this
}

getEventsStartTime(getEventsStartTime: typeof this._getEventsStartTime) {
this._getEventsStartTime = getEventsStartTime
return this
}

getEventsDurationInBars(getEventsDurationInBars: typeof this._getEventsDurationInBars) {
this._getEventsDurationInBars = getEventsDurationInBars
return this
}

build(): Structure {
if (!this._stuctureObject) {
throw new Error('Missing stuctureObject')
}
if (!this._patterns) {
throw new Error('Missing patterns')
}
if (!this._getEventsStartTime) {
throw new Error('Missing getEventsStartTime')
}
if (!this._getEventsDurationInBars) {
throw new Error('Missing getEventsDurationInBars')
}
return new Structure(
new Time(Tone.Time(this._stuctureObject.sampleDuration, 's')),
this._patterns,
this._getEventsStartTime,
this._getEventsDurationInBars
)
}
}

export class Structure {

duration: Time
private readonly startTimes: Time[]
readonly patternsInStructure: PatternInStructure[]

constructor(
patterns: Pattern[],
getEventsStartTime: (pattern: Pattern) => Time | undefined, // TODO en attendant de savoir comment faire les events
getEventsDurationInBars: (pattern: Pattern) => number | undefined, // TODO en attendant de savoir comment faire les events
) {
this.startTimes = []
this.patternsInStructure = []

let currentTime = new Time()
for (const pattern of patterns) {
this.patternsInStructure.push(new PatternInStructure(pattern, this, currentTime, getEventsStartTime(pattern), getEventsDurationInBars(pattern)))
currentTime = currentTime.add(pattern.duration)
}

this.duration = currentTime
private readonly startTimes: Time[]
readonly patternsInStructure: PatternInStructure[]

constructor(
readonly duration: Time,
patterns: Pattern[],
getEventsStartTime: (pattern: Pattern) => Time | undefined, // TODO en attendant de savoir comment faire les events
getEventsDurationInBars: (pattern: Pattern) => number | undefined, // TODO en attendant de savoir comment faire les events
) {
this.startTimes = []
this.patternsInStructure = []

let currentTime = new Time()
for (const pattern of patterns) {
this.patternsInStructure.push(new PatternInStructure(pattern, this, currentTime, getEventsStartTime(pattern), getEventsDurationInBars(pattern)))
currentTime = currentTime.add(pattern.duration)
}

getPatternInStructureAt(time: Time): PatternInStructure | undefined {
this.duration = currentTime
}

// TODO Attention : cette méthode n'est valable pour des time en seconds que si l'enregistrement est pile poil calé sur le tempo, sinon il faut convertir
getPatternInStructureAt(time: Time): PatternInStructure | undefined {

const firstPatternInStructure = this.patternsInStructure[0];
if (time.isBefore(firstPatternInStructure.startTime)) {
return undefined
}
// TODO Attention : cette méthode n'est valable pour des time en seconds que si l'enregistrement est pile poil calé sur le tempo, sinon il faut convertir

for (const patternInStructure of this.patternsInStructure) {
if (time.isBeforeOrEquals(patternInStructure.endTime)) {
return patternInStructure
}
}
const firstPatternInStructure = this.patternsInStructure[0];
if (time.isBefore(firstPatternInStructure.startTime)) {
return undefined
}

return undefined
for (const patternInStructure of this.patternsInStructure) {
if (time.isBeforeOrEquals(patternInStructure.endTime)) {
return patternInStructure
}
}

return undefined
}

static builder(): StructureBuilder {
return new StructureBuilder()
}
}
22 changes: 22 additions & 0 deletions src/app/test/test-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

// Source : https://stackoverflow.com/a/57331494/1655155
export function getKarmaFile(filePath: string): Promise<Blob> {
return new Promise((resolve) => {
const request: XMLHttpRequest = createGetKarmaFileRequest(filePath );

request.onload = async r => {
const blob = new Blob([request.response]);
resolve(blob)
};

// trigger
request.send(null);
})
}

function createGetKarmaFileRequest(filePath: string): XMLHttpRequest {
const request = new XMLHttpRequest();
request.open('GET', 'base/' + filePath, true);
request.responseType = 'arraybuffer'; // maybe also 'text'
return request;
}

0 comments on commit 1449fb3

Please sign in to comment.