use Lilypond to transpose pattern around circle of fifths - lilypond

I want to provide a pattern (e.g., the C major arpeggio, C E G) and have Lilypond automatically show it transposed (as one score) in all 12 scales.
Here's my current attempt:
music = { c' e' g' s }
\new Staff {
\transpose c c { \music }
\transpose c f { \music }
\transpose c bes { \music }
\transpose c ees { \music }
\transpose c aes { \music }
\transpose c des { \music }
\transpose c fis { \music }
\transpose c b { \music }
\transpose c e { \music }
\transpose c a { \music }
\transpose c d { \music }
\transpose c g { \music }
}
I don't know how to add a text above each pattern indicating the transposition key (e.g., C, F, Bb, etc...). I would like the final product to look something like this:
Note: I would like this code to work regardless of the length of the pattern (which could be longer than one measure).

If you want automatic note names, it can be achieved by transposing chords. Something like this produces a similar result to what you show. It is not simple and elegant but it is automatic in the sense that you don't need to know the destination chord previously.
\version "2.19.31"
cOne=\chordmode {c1}
mOne={ c'4 e' g' s }
<<
\new ChordNames{
\transpose c f {\transpose c f { \cOne }}
\transpose c f { \cOne }
\cOne
\transpose c g { \cOne }
\transpose c g { \transpose c g { \cOne }}
\transpose c g { \transpose c g { \transpose c g { \cOne }}}
}
\new Staff {
\transpose c f, {\transpose c f { \mOne }}
\transpose c f { \mOne }
\mOne
\transpose c g { \mOne }
\transpose c g, { \transpose c g { \mOne }}
\transpose c g, { \transpose c g { \transpose c g { \mOne }}}
}
>>

Related

AWS Cloudformation CLI uses shorthand syntax when passing parameters as json file

I am trying to run the following command:
aws cloudformation update-stack --stack-name $stack.Trim('"') --use-previous-template --parameters file://./parameters.json
This is the content of parameters.json (you can copy and paste here to check it is a valid JSON string):
[{"ParameterKey":"directoryName","UsePreviousValue":true},{"ParameterKey":"CodeDeployServiceRole","UsePreviousValue":true},{"ParameterKey":"ApplicationType","UsePreviousValue":true},{"ParameterKey":"EnvironmentCode","UsePreviousValue":true},{"ParameterKey":"InstanceRoleInstanceProfile","UsePreviousValue":true},{"ParameterKey":"VPCID","UsePreviousValue":true},{"ParameterKey":"SecurityGroupList","UsePreviousValue":true},{"ParameterKey":"KeyName","UsePreviousValue":true},{"ParameterKey":"Subnets","UsePreviousValue":true},{"ParameterKey":"dnsIpAddresses","UsePreviousValue":true},{"ParameterKey":"directoryId","UsePreviousValue":true},{"ParameterKey":"directoryBIOS","UsePreviousValue":true},{"ParameterKey":"ScalingTermination","UsePreviousValue":true},{"ParameterKey":"EC2ScaleUpCooldown","UsePreviousValue":true},{"ParameterKey":"AttributeDelayTimeout","UsePreviousValue":true},{"ParameterKey":"CwLowOperator","UsePreviousValue":true},{"ParameterKey":"EBSOptimized","UsePreviousValue":true},{"ParameterKey":"PatchingGroupTag","UsePreviousValue":true},{"ParameterKey":"CwHighOperator","UsePreviousValue":true},{"ParameterKey":"SSMInventoryTag","UsePreviousValue":true},{"ParameterKey":"CwHighEvaluations","UsePreviousValue":true},{"ParameterKey":"EC2ScaleUpAdjustment","UsePreviousValue":true},{"ParameterKey":"CwScalingMetric","UsePreviousValue":true},{"ParameterKey":"HealthyThresholdCount","UsePreviousValue":true},{"ParameterKey":"ImageId","ParameterValue":"ami-0b2e03736f1241bbb"},{"ParameterKey":"CodeDeployServiceRole","UsePreviousValue":true},{"ParameterKey":"directoryName","UsePreviousValue":true},{"ParameterKey":"HealthCheckIntervalSeconds","UsePreviousValue":true},{"ParameterKey":"ReleaseId","UsePreviousValue":true},{"ParameterKey":"UnhealthyThresholdCount","UsePreviousValue":true},{"ParameterKey":"EC2ScaleDownAdjustment","UsePreviousValue":true},{"ParameterKey":"ApplicationType","UsePreviousValue":true},{"ParameterKey":"EnvironmentCode","UsePreviousValue":true},{"ParameterKey":"Environment","UsePreviousValue":true},{"ParameterKey":"EbsVolumeType","UsePreviousValue":true},{"ParameterKey":"BackupsEnabled","UsePreviousValue":true},{"ParameterKey":"CwLowPeriod","UsePreviousValue":true},{"ParameterKey":"HealthCheckType","UsePreviousValue":true},{"ParameterKey":"InstanceRoleInstanceProfile","UsePreviousValue":true},{"ParameterKey":"ServiceLevel","UsePreviousValue":true},{"ParameterKey":"TerminatedInstances","UsePreviousValue":true},{"ParameterKey":"VPCID","UsePreviousValue":true},{"ParameterKey":"HealthCheckPath","UsePreviousValue":true},{"ParameterKey":"CwHighPeriod","UsePreviousValue":true},{"ParameterKey":"HealthCheckGracePeriod","UsePreviousValue":true},{"ParameterKey":"HealthCheckTimeoutSeconds","UsePreviousValue":true},{"ParameterKey":"CustomCWConfig","UsePreviousValue":true},{"ParameterKey":"ScalingMin","UsePreviousValue":true},{"ParameterKey":"SecurityGroupList","UsePreviousValue":true},{"ParameterKey":"CwLowEvaluations","UsePreviousValue":true},{"ParameterKey":"directoryBIOS","UsePreviousValue":true},{"ParameterKey":"CustomSSMStepCount","UsePreviousValue":true},{"ParameterKey":"ScalingMax","UsePreviousValue":true},{"ParameterKey":"InstanceType","UsePreviousValue":true},{"ParameterKey":"EncryptEBSVolume","UsePreviousValue":true},{"ParameterKey":"SSMRefreshFrequency","UsePreviousValue":true},{"ParameterKey":"CwHighThreshold","UsePreviousValue":true},{"ParameterKey":"CustomSSMSteps","UsePreviousValue":true},{"ParameterKey":"MinInstancesInService","UsePreviousValue":true},{"ParameterKey":"MatcherCode","UsePreviousValue":true},{"ParameterKey":"EbsVolumeSize","UsePreviousValue":true},{"ParameterKey":"EC2ScaleDownCooldown","UsePreviousValue":true},{"ParameterKey":"Iops","UsePreviousValue":true},{"ParameterKey":"KeyName","UsePreviousValue":true},{"ParameterKey":"Subnets","UsePreviousValue":true},{"ParameterKey":"dnsIpAddresses","UsePreviousValue":true},{"ParameterKey":"CWLogRetention","UsePreviousValue":true},{"ParameterKey":"EnableRackspaceTicket","UsePreviousValue":true},{"ParameterKey":"CwLowThreshold","UsePreviousValue":true},{"ParameterKey":"directoryId","UsePreviousValue":true},{"ParameterKey":"ScalingNotificationTopic","UsePreviousValue":true},{"ParameterKey":"LoadBalancerFullName","UsePreviousValue":true}]
I get this when I run the command:
aws :
At line:1 char:1
+ aws cloudformation update-stack --stack-name $stack.Trim('"') --templ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Error parsing parameter '--parameters': Expected: '=', received: 'ÿ' for input:
ÿþ[ { " P a r a m e t e r K e y " : " d i r e c t o r y N a m e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C o d e D e p l o y S e r v i c e R o l e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r
a m e t e r K e y " : " A p p l i c a t i o n T y p e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " E n v i r o n m e n t C o d e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y "
: " I n s t a n c e R o l e I n s t a n c e P r o f i l e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " V P C I D " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " S e c u r i t
y G r o u p L i s t " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " K e y N a m e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " S u b n e t s " , " U s e P r e v i o u s V a
l u e " : t r u e } , { " P a r a m e t e r K e y " : " d n s I p A d d r e s s e s " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " d i r e c t o r y I d " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r
a m e t e r K e y " : " d i r e c t o r y B I O S " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " S c a l i n g T e r m i n a t i o n " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y
" : " E C 2 S c a l e U p C o o l d o w n " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " A t t r i b u t e D e l a y T i m e o u t " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " :
" C w L o w O p e r a t o r " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " E B S O p t i m i z e d " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " P a t c h i n g G r o u p T
a g " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C w H i g h O p e r a t o r " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " S S M I n v e n t o r y T a g " , " U s e P r e v
i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C w H i g h E v a l u a t i o n s " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " E C 2 S c a l e U p A d j u s t m e n t " , " U s e P r e v i o u
s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C w S c a l i n g M e t r i c " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " H e a l t h y T h r e s h o l d C o u n t " , " U s e P r e v i o u s V a l u
e " : t r u e } , { " P a r a m e t e r K e y " : " I m a g e I d " , " P a r a m e t e r V a l u e " : " a m i - 0 b 2 e 0 3 7 3 6 f 1 2 4 1 b b b " } , { " P a r a m e t e r K e y " : " C o d e D e p l o y S e r v i c e R o l e " , " U s e P r e v i o u
s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " d i r e c t o r y N a m e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " H e a l t h C h e c k I n t e r v a l S e c o n d s " , " U s e P r e v i o u s V
a l u e " : t r u e } , { " P a r a m e t e r K e y " : " R e l e a s e I d " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " U n h e a l t h y T h r e s h o l d C o u n t " , " U s e P r e v i o u s V a l u e " : t r
u e } , { " P a r a m e t e r K e y " : " E C 2 S c a l e D o w n A d j u s t m e n t " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " A p p l i c a t i o n T y p e " , " U s e P r e v i o u s V a l u e " : t r u e } ,
{ " P a r a m e t e r K e y " : " E n v i r o n m e n t C o d e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " E n v i
r o n m e n t " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " E b s V o l u m e T y p e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " B a c k u p s E n a b l e d " , " U s e
P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C w L o w P e r i o d " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " H e a l t h C h e c k T y p e " , " U s e P r e v i o u s V a l u e " :
t r u e } , { " P a r a m e t e r K e y " : " I n s t a n c e R o l e I n s t a n c e P r o f i l e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " S e r v i c e L e v e l " , " U s e P r e v i o u s V a l u e " : t
r u e } , { " P a r a m e t e r K e y " : " T e r m i n a t e d I n s t a n c e s " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " V P C I D " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K
e y " : " H e a l t h C h e c k P a t h " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C w H i g h P e r i o d " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " H e a l t h C h
e c k G r a c e P e r i o d " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " H e a l t h C h e c k T i m e o u t S e c o n d s " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C u
s t o m C W C o n f i g " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " S c a l i n g M i n " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " S e c u r i t y G r o u p L i s t "
, " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C w L o w E v a l u a t i o n s " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " d i r e c t o r y B I O S " , " U s e P r e v i o u
s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C u s t o m S S M S t e p C o u n t " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " S c a l i n g M a x " , " U s e P r e v i o u s V a l u e " : t r u e
} , { " P a r a m e t e r K e y " : " I n s t a n c e T y p e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " E n c r y p t E B S V o l u m e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r
K e y " : " S S M R e f r e s h F r e q u e n c y " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C w H i g h T h r e s h o l d " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : "
C u s t o m S S M S t e p s " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " M i n I n s t a n c e s I n S e r v i c e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " M a t c h e
r C o d e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " E b s V o l u m e S i z e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " E C 2 S c a l e D o w n C o o l d o w n " ,
" U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " I o p s " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " K e y N a m e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r
a m e t e r K e y " : " S u b n e t s " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " d n s I p A d d r e s s e s " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C W L o g R e
t e n t i o n " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " E n a b l e R a c k s p a c e T i c k e t " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C w L o w
T h r e s h o l d " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " d i r e c t o r y I d " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " S c a l i n g N o t i f i c a t i o n T
o p i c " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " L o a d B a l a n c e r F u l l N a m e " , " U s e P r e v i o u s V a l u e " : t r u e } ]
^
I have run the command using --debug and noticed that it tries to parse the parameters using shorthand syntax:
2019-04-15 14:11:36,069 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.cloudformation.update-stack: calling handler <awscli.argprocess.ParamShorthandParser object at 0x0000020212160F28>
2019-04-15 14:11:36,070 - MainThread - awscli.argprocess - DEBUG - Parsing param --parameters as shorthand
I cannot find any way to force the CLI to parse the parameters using JSON syntax rather than shorthand. From the docs, it looks like it should do that automatically.
Any ideas why it tries to use the shorthand syntax?
It looks like the issue was the encoding for parameters.json.
I think the CLI could not parse parameters.json due to the encoding of the file, and was therefore trying to parse the parameters using the shorthand syntax rather than the JSON syntax.
I created the file using the following code:
$parameters = "{""ParameterKey"":""directoryName"",""UsePreviousValue"":true},{""ParameterKey"":""CodeDeployServiceRole"",""UsePreviousValue"":true},{""ParameterKey"":""ApplicationType"",""UsePreviousValue"":true},{""ParameterKey"":""EnvironmentCode"",""UsePreviousValue"":true},{""ParameterKey"":""InstanceRoleInstanceProfile"",""UsePreviousValue"":true},{""ParameterKey"":""VPCID"",""UsePreviousValue"":true},{""ParameterKey"":""SecurityGroupList"",""UsePreviousValue"":true},{""ParameterKey"":""KeyName"",""UsePreviousValue"":true},{""ParameterKey"":""Subnets"",""UsePreviousValue"":true},{""ParameterKey"":""dnsIpAddresses"",""UsePreviousValue"":true},{""ParameterKey"":""directoryId"",""UsePreviousValue"":true},{""ParameterKey"":""directoryBIOS"",""UsePreviousValue"":true},"
# generate json file with parameters for stack
foreach ($parameter in $stackJson.Stacks.Parameters){
$parameterKey = $parameter.ParameterKey
if ($parameterKey -eq "ImageId"){
$parameters += "{""ParameterKey"":""$parameterKey"",""ParameterValue"":""$latestAmiId""},"
}
else {
$parameters += "{""ParameterKey"":""$parameterKey"",""UsePreviousValue"":true},"
}
}
$parameters = $parameters.TrimEnd(',')
$parameters = "[" + $parameters + "]"
#$parameters = ConvertFrom-Json $parameters
$parameters | Out-File .\parameters.json
Adding -Encoding ascii to the Out-File command solved the issue.

Haskell - Passing a function as an argument

so in haskell I have the following 2 functions made (they are just performing some math operations)
cubicQ :: Float -> Float -> Float -> Float
cubicQ a b c = (3*a*c - b**2) / (9*a**2)
cubicR :: Float -> Float -> Float -> Float -> Float
cubicR a b c d = (9*a*b*c - 27*(a**2)*d-2*b**3)
I am to make a third function cubicS that has a requirement that the function be of type Float -> Float -> Float and it calculates its output from q and r, which is the output for cubicQ and cubicR. How would I pass the functions cubicQ and cubicR as arguments q and r in cubicS? Below is what I have tried so far but I am stumped. Any help would be greatly appreciated.
cubicS q r = (r+ (q**3+r**2)**(1/2))**(1/3)
where q = (cubicQ a b c d)
r = (cubicR a b c)
try this:
cubicQ a b c = (3*a*c - b**2) / (9*a**2)
cubicR a b c d = (9*a*b*c - 27*(a**2)*d-2*b**3)
cubicS q r = (r+ (q**3+r**2)**(1/2))**(1/3)
f a b c d = cubicS (cubicQ a b c) (cubicR a b c d)
main = do print $ f 1 2 3 4
or:
cubicS a b c d = (r+ (q**3+r**2)**(1/2))**(1/3)
where q = cubicQ a b c
r = cubicR a b c d
or:
cubicS a b c d =
let q = cubicQ a b c
r = cubicR a b c d
in (r+ (q**3+r**2)**(1/2))**(1/3)
see:
cubicQ :: Float -> Float -> Float -> Float
cubicQ a b c = (3*a*c - b**2) / (9*a**2)
cubicR :: Float -> Float -> Float -> Float -> Float
cubicR a b c d = (9*a*b*c - 27*(a**2)*d-2*b**3)
cubicS :: Float -> Float -> Float -> Float -> Float
cubicS a b c d =
let q = cubicQ a b c
r = cubicR a b c d
in
(r+ (q**3+r**2)**(1/2))**(1/3)
main = do print $ cubicS 1.1 2.2 3.3 4.4
output:
9.736999e-2
and if you restricted to cubicS being cubicS: Float -> Float -> Float:
cubicQ a b c = (3*a*c - b**2) / (9*a**2)
cubicR a b c d = (9*a*b*c - 27*(a**2)*d-2*b**3)
cubicS q r = (r+ (q**3+r**2)**(1/2))**(1/3)
cureS a b c d = cubicS q r
where q = cubicQ a b c
r = cubicR a b c d
main = do print $ cureS 1.1 2.2 3.3 4.4

How can I do matching on a field containing text that alternates with spaces?

I have an Elasticsearch v2.4.1 index in which I store values from a JSON feed. Sometimes I get values separated by spaces in some fields, like:
"titulo" : "E l a ñ o q u e e l m e r c a d o d e j ó d e a s u s t a r"
This happens around 15% of the time and prevents queries such as:
localhost:9200/indice/_search?q=titulo:mercado
To match the document above.
I think the problem could be solved by using some sort of CharFilter, I thought of the N-gram filter but that does the opposite. I know this might be complex since ES should, at some level, infer the language (or maybe I could specify it); deal with ambiguities and so on...
Another examples of the same:
"title" : "El g a l a r d ó n se e n t r e g a r á el p r ó x i m o día 2 4"
"title" : "G a m a a c t u a l i z a d a d e b o m b a s d e calor A q u a t e r m i c"
"title" : "K a s p e r s k y : m á s q u e a n t i v i r u s"

Receiving data with spaces, thru sockets

I'm using C++ with QT4 for this. And when I try to send large html files(in this case, 8kb), the process of sending and receiving work well. But the file received come with spaces between each character of the html file. Here an example, the file is sent like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">a</p></body></html>
and it's received, like this:
¼ < ! D O C T Y P E H T M L P U B L I C " - / / W 3 C / / D T D H T M L 4 . 0 / / E N " " h t t p : / / w w w . w 3 . o r g / T R / R E C - h t m l 4 0 / s t r i c t . d t d " >
< h t m l > < h e a d > < m e t a n a m e = " q r i c h t e x t " c o n t e n t = " 1 " / > < s t y l e t y p e = " t e x t / c s s " >
p , l i { w h i t e - s p a c e : p r e - w r a p ; }
< / s t y l e > < / h e a d > < b o d y s t y l e = " f o n t - f a m i l y : ' M S S h e l l D l g 2 ' ; f o n t - s i z e : 8 . 2 5 p t ; f o n t - w e i g h t : 4 0 0 ; f o n t - s t y l e : n o r m a l ; " >
< p s t y l e = " - q t - p a r a g r a p h - t y p e : e m p t y ; m a r g i n - t o p : 0 p x ; m a r g i n - b o t t o m : 0 p x ; m a r g i n - l e f t : 0 p x ; m a r g i n - r i g h t : 0 p x ; - q t - b l o c k - i n d e n t : 0 ; t e x t - i n d e n t : 0 p x ; " > < / p > < / b o d y > < / h t m l >
the code i'm using for sending and receiving:
Sending code:
qDebug() << "Connected. Sending file to the server"; QString text = ui->QuestHtmlText->toPlainText();
if(text.length() < 1024)
{
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out << quint16(0) << QUESTION_HTML;
out << text;
out.device()->seek(0);
out << quint16(block.size() - sizeof(quint16));
qDebug() << "Block size: " << block.size();
socket.write(block);
return;
}
for(int i = 0; i < text.length(); i+=1024)
{
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out << quint16(0) << QUESTION_HTML;
if((text.length() - i) > 1024)
out << text.mid(i, i+1024);
else
out << text.right(1024 - i);
out.device()->seek(0);
out << quint16(block.size() - sizeof(quint16));
qDebug() << "Block size: " << block.size();
socket.write(block);
}
Receiving code:
qDebug() << "Writing File";
QDataStream in(this);
QString temp = "Teste.html", text;
QFile myFile(".//Questions//" + temp);
myFile.open(QIODevice::WriteOnly);
QDataStream out(&myFile);
while(!in.atEnd())
{
in >> text;
out << text;
}
I did opened a post before, here: Sending data through socket spaces, receiving with spaces
People stopped helping me out. By the way, i didnt feel like my question was completly answered. So I opened another post.
I also looked in the FAQ section to see what should I do in this case. But with no sucess.
Anyway, my question now is: should I remove the quint16? what should I use to determine the size of the incoming packet then ?
Thanks, and I'm sorry about the mistakes I may have made.
The stuff you are getting back in the file is not your original text, but QString serialization form, which is unsuprisingly UTF-16. If you want your text back, read the input QDataStream back to QString and save that into file.
While prefixing your data with a length is generally a good idea, it is absolutely redundant with QString >> QDataStream. Read up something here or here. Moreover you have developed a mind boggingly obfuscated way which i suspect is doing nothing. QByteArray is not implementing QIODevice (indeed, why it should) so your out.device()->seek() is a base virtual implementation, empty and just returning true. I won't be surprised if your length "header" is found at the end of your serialization dump file.
Edit: i think that your html transport might start working correctly only by leaving out the confused quint operation completely and use out QTextStream instead of QByteStream.
I posted the solution for my case in the other post.
Thanks you all for the attention

Sending data through socket spaces, receiving with spaces

I'm using C++ with QT4 for this. And when I try to send large html files(in this case, 8kb), the process of sending and receiving work well. But the file received come with spaces between each character of the html file. Here an example,
the file is sent like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">a</p></body></html>
and it's received, like this:
¼ < ! D O C T Y P E H T M L P U B L I C " - / / W 3 C / / D T D H T M L 4 . 0 / / E N " " h t t p : / / w w w . w 3 . o r g / T R / R E C - h t m l 4 0 / s t r i c t . d t d " >
< h t m l > < h e a d > < m e t a n a m e = " q r i c h t e x t " c o n t e n t = " 1 " / > < s t y l e t y p e = " t e x t / c s s " >
p , l i { w h i t e - s p a c e : p r e - w r a p ; }
< / s t y l e > < / h e a d > < b o d y s t y l e = " f o n t - f a m i l y : ' M S S h e l l D l g 2 ' ; f o n t - s i z e : 8 . 2 5 p t ; f o n t - w e i g h t : 4 0 0 ; f o n t - s t y l e : n o r m a l ; " >
< p s t y l e = " - q t - p a r a g r a p h - t y p e : e m p t y ; m a r g i n - t o p : 0 p x ; m a r g i n - b o t t o m : 0 p x ; m a r g i n - l e f t : 0 p x ; m a r g i n - r i g h t : 0 p x ; - q t - b l o c k - i n d e n t : 0 ; t e x t - i n d e n t : 0 p x ; " > < / p > < / b o d y > < / h t m l >
the code i'm using for sending and receiving:
Sending code:
qDebug() << "Connected. Sending file to the server";
QString text = ui->QuestHtmlText->toPlainText();
if(text.length() < 1024)
{
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out << quint16(0) << QUESTION_HTML;
out << text;
out.device()->seek(0);
out << quint16(block.size() - sizeof(quint16));
qDebug() << "Block size: " << block.size();
socket.write(block);
return;
}
for(int i = 0; i < text.length(); i+=1024)
{
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out << quint16(0) << QUESTION_HTML;
if((text.length() - i) > 1024)
out << text.mid(i, i+1024);
else
out << text.right(1024 - i);
out.device()->seek(0);
out << quint16(block.size() - sizeof(quint16));
qDebug() << "Block size: " << block.size();
socket.write(block);
}
Receiving code:
qDebug() << "Writing File";
QDataStream in(this);
QString temp = "Teste.html", text;
QFile myFile(".//Questions//" + temp);
myFile.open(QIODevice::WriteOnly);
QDataStream out(&myFile);
while(!in.atEnd())
{
in >> text;
out << text;
}
#Eugen i suspect the quint16 is either not written at all or is at the end of the file. Read below.
#Patrick don't repost only because you feel like not being served fast enough. Stackowerflow is not a hotline.
The stuff you are getting back in the file is not your original text, but QString serialization form, which is unsuprisingly UTF-16. If you want your text back, read the input QDataStream back to QString and save that into file.
While prefixing your data with a length is generally a good idea, it is absolutely redundant with QString >> QDataStream. Read up something here or here. Moreover you have developed a mind boggingly obfuscated way which i suspect is doing nothing. QByteArray is not implementing QIODevice (indeed, why it should) so your out.device()->seek() is a base virtual implementation, empty and just returning true. I won't be surprised if your length "header" is found at the end of your serialization dump file.
Edit: i think that your html transport might start working correctly only by leaving out the confused quint operation completely and use out QTextStream instead of QByteStream.
I bet there are not spaces between characters (but 0s) & you get the extra chars due to your use of quint16.
I solved the problem writing it to a file and getting this file to a QByteArray, and sending the QbyteArray entirely to the socket.